Skip to content

Commit

Permalink
Merge branch 'main' into examples
Browse files Browse the repository at this point in the history
* main:
  docs: networking basics (#612)
  docs: wording in project name (#610)
  feat: Auth config for build images (#602)
  chore: sync governance files (#608)
  • Loading branch information
mdelapenya committed Nov 9, 2022
2 parents d801fde + 5ff899f commit ed0121e
Show file tree
Hide file tree
Showing 35 changed files with 398 additions and 26 deletions.
10 changes: 5 additions & 5 deletions .github/ISSUE_TEMPLATE/bug_report.yml
@@ -1,7 +1,7 @@
name: Bug Report
name: Bug report
description: File a bug report
title: "[Bug]: "
labels: ["type/bug"]
labels: ["bug"]
body:
- type: markdown
attributes:
Expand Down Expand Up @@ -36,15 +36,15 @@ body:
- type: input
id: host-arch
attributes:
label: Host Arch
label: Host arch
description: Which architecture are you using?
placeholder: e.g. x86, ARM
validations:
required: true
- type: input
id: go-version
attributes:
label: Go Version
label: Go version
description: Which Go version are you using?
placeholder: e.g. 1.18
validations:
Expand Down Expand Up @@ -81,7 +81,7 @@ body:
- type: textarea
id: additional-information
attributes:
label: Additional Information
label: Additional information
description: |
Any links or references to have more context about the issue.
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/enhancement.yml
@@ -1,7 +1,7 @@
name: Enhancement
description: Suggest an enhancement
title: "[Enhancement]: "
labels: ["type/enhancement"]
labels: ["enhancement"]
body:
- type: markdown
attributes:
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature.yml
@@ -1,7 +1,7 @@
name: Feature
description: Suggest a new feature
title: "[Feature]: "
labels: ["type/feature"]
labels: ["feature"]
body:
- type: markdown
attributes:
Expand Down
40 changes: 40 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,40 @@
<!-- Type of change
Please label this PR with one of the existing labels, depending on the scope of your change
-->

## What does this PR do?

<!-- Mandatory
Explain here the changes you made on the PR. Please explain the WHAT: patterns used, algorithms implemented, design architecture, etc.
-->

## Why is it important?

<!-- Mandatory
Explain here the WHY, or the rationale/motivation for the changes.
-->

## Related issues

<!-- Recommended
Link related issues below. Insert the issue link or reference after the word "Closes" if merging this should automatically close it.
- Closes #123
- Relates #123
- Requires #123
- Supersedes #123
-->
-

<!-- Recommended
## How to test this PR
Explain here how this PR will be tested by the reviewer: commands, dependencies, steps, etc.
-->


<!-- Optional
## Follow-ups
Add here any thought that you consider could be identified as an actionable step once this PR is merged.
-->
1 change: 1 addition & 0 deletions .github/release-drafter.yml
Expand Up @@ -6,6 +6,7 @@ template: |
categories:
- title: 🚀 Features
labels:
- 'enhancement'
- 'feature'
- title: ⚠️ Breaking Changes
labels:
Expand Down
2 changes: 1 addition & 1 deletion .github/settings.yml
Expand Up @@ -181,7 +181,7 @@ branches:
# Required. Require branches to be up to date before merging.
strict: true
# Required. The list of status checks to require in order to merge into this branch
contexts: ["static-analysis", "tests (1.x, ubuntu-latest)"]
contexts: ["static-analysis", "test (1.x, ubuntu-latest)"]
# Required. Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable.
enforce_admins: false
# Prevent merge commits from being pushed to matching branches
Expand Down
27 changes: 17 additions & 10 deletions container.go
Expand Up @@ -65,21 +65,23 @@ type Container interface {

// ImageBuildInfo defines what is needed to build an image
type ImageBuildInfo interface {
GetContext() (io.Reader, error) // the path to the build context
GetDockerfile() string // the relative path to the Dockerfile, including the fileitself
ShouldPrintBuildLog() bool // allow build log to be printed to stdout
ShouldBuildImage() bool // return true if the image needs to be built
GetBuildArgs() map[string]*string // return the environment args used to build the from Dockerfile
GetContext() (io.Reader, error) // the path to the build context
GetDockerfile() string // the relative path to the Dockerfile, including the fileitself
ShouldPrintBuildLog() bool // allow build log to be printed to stdout
ShouldBuildImage() bool // return true if the image needs to be built
GetBuildArgs() map[string]*string // return the environment args used to build the from Dockerfile
GetAuthConfigs() map[string]types.AuthConfig // return the auth configs to be able to pull from an authenticated docker registry
}

// FromDockerfile represents the parameters needed to build an image from a Dockerfile
// rather than using a pre-built one
type FromDockerfile struct {
Context string // the path to the context of of the docker build
ContextArchive io.Reader // the tar archive file to send to docker that contains the build context
Dockerfile string // the path from the context to the Dockerfile for the image, defaults to "Dockerfile"
BuildArgs map[string]*string // enable user to pass build args to docker daemon
PrintBuildLog bool // enable user to print build log
Context string // the path to the context of of the docker build
ContextArchive io.Reader // the tar archive file to send to docker that contains the build context
Dockerfile string // the path from the context to the Dockerfile for the image, defaults to "Dockerfile"
BuildArgs map[string]*string // enable user to pass build args to docker daemon
PrintBuildLog bool // enable user to print build log
AuthConfigs map[string]types.AuthConfig // enable auth configs to be able to pull from an authenticated docker registry
}

type ContainerFile struct {
Expand Down Expand Up @@ -230,6 +232,11 @@ func (c *ContainerRequest) GetDockerfile() string {
return f
}

// GetAuthConfigs returns the auth configs to be able to pull from an authenticated docker registry
func (c *ContainerRequest) GetAuthConfigs() map[string]types.AuthConfig {
return c.FromDockerfile.AuthConfigs
}

func (c *ContainerRequest) ShouldBuildImage() bool {
return c.FromDockerfile.Context != "" || c.FromDockerfile.ContextArchive != nil
}
Expand Down
45 changes: 45 additions & 0 deletions container_test.go
Expand Up @@ -12,6 +12,7 @@ import (
"testing"
"time"

"github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert"

"github.com/testcontainers/testcontainers-go/wait"
Expand Down Expand Up @@ -127,6 +128,50 @@ func Test_GetDockerfile(t *testing.T) {
}
}

func Test_GetAuthConfigs(t *testing.T) {
type TestCase struct {
name string
ExpectedAuthConfigs map[string]types.AuthConfig
ContainerRequest ContainerRequest
}

testTable := []TestCase{
{
name: "defaults to no auth",
ExpectedAuthConfigs: nil,
ContainerRequest: ContainerRequest{
FromDockerfile: FromDockerfile{},
},
},
{
name: "will specify credentials",
ExpectedAuthConfigs: map[string]types.AuthConfig{
"https://myregistry.com/": {
Username: "username",
Password: "password",
},
},
ContainerRequest: ContainerRequest{
FromDockerfile: FromDockerfile{
AuthConfigs: map[string]types.AuthConfig{
"https://myregistry.com/": {
Username: "username",
Password: "password",
},
},
},
},
},
}

for _, testCase := range testTable {
t.Run(testCase.name, func(t *testing.T) {
cfgs := testCase.ContainerRequest.GetAuthConfigs()
assert.Equal(t, testCase.ExpectedAuthConfigs, cfgs)
})
}
}

func Test_BuildImageWithContexts(t *testing.T) {
type TestCase struct {
Name string
Expand Down
1 change: 1 addition & 0 deletions docker.go
Expand Up @@ -879,6 +879,7 @@ func (p *DockerProvider) BuildImage(ctx context.Context, img ImageBuildInfo) (st
buildOptions := types.ImageBuildOptions{
BuildArgs: img.GetBuildArgs(),
Dockerfile: img.GetDockerfile(),
AuthConfigs: img.GetAuthConfigs(),
Context: buildContext,
Tags: []string{repoTag},
Remove: true,
Expand Down

0 comments on commit ed0121e

Please sign in to comment.