github.com/goreleaser/goreleaser@v1.25.1/www/docs/cookbooks/override-image-name.md (about) 1 # Override hardcoded registry and image name ? 2 3 If you are curious about how to avoid hard-coded registry and image names within 4 your `.goreleaser.yml`, we have good news for you. Here is the solution. Suppose 5 you haven't been aware of GoReleaser Action, which allows you to install 6 GoReleaser binary in your workflow easily. In that case, this is the right time 7 to be mindful of that because, in this section, we'll give an example through 8 GoReleaser's GitHub Action. 9 10 > To get more detail about the GoReleaser's GitHub Action, please 11 > [see](https://github.com/goreleaser/goreleaser-action). 12 13 As you can see from the description 14 [here](https://github.com/goreleaser/goreleaser-action#environment-variables), 15 you can pass environment variables to the GoReleaser to use within the 16 `.goreleaser.yml` via syntax `{{ .Env.<something> }}`. So, let' define our 17 registry and image names as an [environment variable in the 18 workflow](https://docs.github.com/en/actions/learn-github-actions/environment-variables), 19 then pass those to the GoReleaser via `env` section of the GoReleaser's GitHub 20 Action like the following: 21 22 ```YAML 23 jobs: 24 # use goreleaser to cross-compile go binaries and add them to GitHub release 25 goreleaser: 26 runs-on: ubuntu-latest 27 env: 28 REGISTRY: "ghcr.io" 29 IMAGE_NAME: "google/addlicense" 30 ... 31 - name: Run GoReleaser 32 uses: goreleaser/goreleaser-action@v4 33 with: 34 distribution: goreleaser 35 version: latest 36 args: release --clean 37 env: 38 REGISTRY: ${{ env.REGISTRY }} 39 IMAGE: ${{ env.IMAGE_NAME }} 40 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 41 ``` 42 43 Once you pass those to the GoReleaser, you can access them within your 44 `.goreleaser.yml` file as I mentioned above, here is the example of this: 45 46 ```YAML 47 dockers: 48 - image_templates: 49 - '{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-amd64' 50 dockerfile: Dockerfile.goreleaser 51 use: buildx 52 build_flag_templates: 53 - "--pull" 54 - "--label=org.opencontainers.image.created={{.Date}}" 55 - "--label=org.opencontainers.image.name={{.ProjectName}}" 56 - "--label=org.opencontainers.image.revision={{.FullCommit}}" 57 - "--label=org.opencontainers.image.version={{.Version}}" 58 - "--label=org.opencontainers.image.source={{.GitURL}}" 59 - "--platform=linux/amd64" 60 ``` 61 62 That's all we need to do, you even might be surprised when you notice that how 63 easy it is to overcome this issue.