Skip to content

Commit

Permalink
provider: adjust credential logic for hub-stage
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Santos <nick.santos@docker.com>
  • Loading branch information
nicks committed Aug 28, 2024
1 parent cb36b39 commit 04470be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/acctest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ name: Acceptance Tests

on:
workflow_dispatch:
inputs:
ref:
inputs:
ref:
description: 'The ref to checkout e.g the SHA of a fork in PR'
type: string
required: false
default: 'main'
tests:
tests:
description: 'The TESTS pattern to supply to `make testacc`. Default is all tests.'
type: string
required: false
Expand Down Expand Up @@ -39,11 +39,16 @@ jobs:
terraform_version: ${{ inputs.terraform-version }}
terraform_wrapper: false

- uses: docker/login-action@v2
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: index-stage.docker.io

- run: |
make testacc TESTS='${{ inputs.tests }}'
env:
DOCKER_USERNAME: "${{ vars.DOCKER_USERNAME }}"
DOCKER_PASSWORD: "${{ secrets.DOCKER_PASSWORD }}"
DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }}
DOCKER_HUB_HOST: "hub-stage.docker.com"
TF_ACC: "1"
timeout-minutes: 30
4 changes: 4 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
var hostRegexp = regexp.MustCompile(`^[a-zA-Z0-9:.-]+$`)

const dockerHubConfigfileKey = "https://index.docker.io/v1/"
const dockerHubStageConfigfileKey = "index-stage.docker.io"
const dockerHubHost = "hub.docker.com"
const dockerHubStageHost = "hub-stage.docker.com"

// Ensure DockerProvider satisfies various provider interfaces.
var (
Expand Down Expand Up @@ -145,6 +147,8 @@ func (p *DockerProvider) Configure(ctx context.Context, req provider.ConfigureRe
configfileKey := host
if host == dockerHubHost {
configfileKey = dockerHubConfigfileKey
} else if host == dockerHubStageHost {
configfileKey = dockerHubStageConfigfileKey
}

// Use the getUserCreds function to retrieve credentials from Docker config
Expand Down
3 changes: 0 additions & 3 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,4 @@ func testAccPreCheck(t *testing.T) {
if v := os.Getenv("DOCKER_USERNAME"); v == "" {
t.Fatal("DOCKER_USERNAME must be set for acceptance tests")
}
if v := os.Getenv("DOCKER_PASSWORD"); v == "" {
t.Fatal("DOCKER_PASSWORD must be set for acceptance tests")
}
}

0 comments on commit 04470be

Please sign in to comment.