Skip to content

Instantly share code, notes, and snippets.

@dizys
Last active August 4, 2021 09:45
Show Gist options
  • Save dizys/78b5cf2209081d85541985b04166e57c to your computer and use it in GitHub Desktop.
Save dizys/78b5cf2209081d85541985b04166e57c to your computer and use it in GitHub Desktop.
Github Actions + Build go app with private repo in Docker

Passing GitHub secrets in Actions step

      - name: Build domain service image
        uses: docker/build-push-action@v2
        with:
          push: true
          context: domain-service
          tags: |
            dizy/ambassador-test-domain-service:latest
            dizy/ambassador-test-domain-service:${{ github.sha }}
          secrets: |
            "github_username=${{ secrets.PERSONAL_GITHUB_USERNAME }}"
            "github_token=${{ secrets.PERSONAL_GITHUB_ACCESS_TOKEN }}"

Use secrets in Dockerfile

RUN --mount=type=secret,id=github_username --mount=type=secret,id=github_token git config --global url."https://$(cat /run/secrets/github_username):$(cat /run/secrets/github_token)@github.com".insteadOf "https://github.com"

# Do your normal go building stuff...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment