Skip to content

Commit

Permalink
Use version of go specified in go.mod when building the docker image (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
hughns authored Jan 20, 2025
1 parent 3a3b094 commit 188c9a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Build and publish Docker image

on:
push:
branches: [main]

env:
REGISTRY: ghcr.io
Expand Down Expand Up @@ -45,11 +44,16 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@0f069ddc17b8eb78586b08a7fe335fd54649e2d3

- name: Get go version
run: echo "GO_VERSION=$(go mod edit -json | jq -r .Go)" >> $GITHUB_ENV

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
push: ${{github.ref == 'refs/heads/main'}} # only push on main branch
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GO_VERSION=${{ env.GO_VERSION }}
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM golang:1.23-alpine as builder
ARG GO_VERSION="build-arg-must-be-provided"

FROM golang:${GO_VERSION}-alpine AS builder

WORKDIR /proj

Expand Down

0 comments on commit 188c9a7

Please sign in to comment.