From 04470be20170a90a98224410eaa457942bbeceb4 Mon Sep 17 00:00:00 2001 From: Nick Santos Date: Wed, 28 Aug 2024 13:00:33 -0400 Subject: [PATCH] provider: adjust credential logic for hub-stage Signed-off-by: Nick Santos --- .github/workflows/acctest.yaml | 15 ++++++++++----- internal/provider/provider.go | 4 ++++ internal/provider/provider_test.go | 3 --- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/acctest.yaml b/.github/workflows/acctest.yaml index 01e7fd7..ac756c7 100644 --- a/.github/workflows/acctest.yaml +++ b/.github/workflows/acctest.yaml @@ -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 @@ -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 diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 41ec017..772512a 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -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 ( @@ -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 diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index 1c93175..0ce3fb9 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -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") - } }