Skip to content

Commit

Permalink
Use multi-arch Docker images (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored Nov 7, 2024
1 parent 6e23012 commit 9854a2e
Showing 4 changed files with 78 additions and 49 deletions.
58 changes: 36 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@ on:

jobs:
docker:
name: Docker
timeout-minutes: 20
name: Docker (${{ matrix.branch }})
timeout-minutes: 50

strategy:
fail-fast: false
@@ -29,7 +29,6 @@ jobs:
- master
- release-branch.go1.23
- release-branch.go1.22
- release-branch.go1.21

runs-on: ${{ matrix.os }}

@@ -43,45 +42,54 @@ jobs:
- name: Setup QEMU
uses: docker/setup-qemu-action@v3

- name: Login into Docker registries
if: github.event_name != 'pull_request'
run: |
docker login --username aleksi --password ${{ secrets.DOCKERHUB_TOKEN }}
docker login ghcr.io --username aleksi --password ${{ secrets.GITHUB_TOKEN }}
- name: Start BuildKit builder
run: make docker-up

- name: Build Docker images
- name: Build Docker images for PR
if: github.event_name == 'pull_request'
run: make docker-build

# skip push for PRs
# move to `publish` job
# TODO https://github.com/AlekSi/golang-tip/issues/8

- name: Login into Docker registries
- name: Build Docker images for Docker Hub
if: github.event_name != 'pull_request'
run: |
docker login --username aleksi --password ${{ secrets.DOCKERHUB_TOKEN }}
docker login ghcr.io --username aleksi --password ${{ secrets.GITHUB_TOKEN }}
run: make docker-build
env:
DOCKER_PLATFORM: linux/amd64,linux/arm64
DOCKER_OUTPUT: type=image,push=true
DOCKER_TAG: aleksi/golang-tip:${{ env.GO_BRANCH }}

- name: Upload Docker images
- name: Build Docker images for ghcr.io
if: github.event_name != 'pull_request'
run: |
docker tag golang-tip:${{ env.GO_BRANCH }} aleksi/golang-tip:${{ env.GO_BRANCH }}
docker tag golang-tip:${{ env.GO_BRANCH }} ghcr.io/aleksi/golang-tip:${{ env.GO_BRANCH }}
docker push aleksi/golang-tip:${{ env.GO_BRANCH }}
docker push ghcr.io/aleksi/golang-tip:${{ env.GO_BRANCH }}
run: make docker-build
env:
DOCKER_PLATFORM: linux/amd64,linux/arm64
DOCKER_OUTPUT: type=image,push=true
DOCKER_TAG: ghcr.io/aleksi/golang-tip:${{ env.GO_BRANCH }}

# skip push for PRs
# move to `publish` job
# TODO https://github.com/AlekSi/golang-tip/issues/8

targz:
name: TarGz
timeout-minutes: 20
name: TarGz (${{ matrix.branch }}, ${{ matrix.os }}, ${{ matrix.goroot }})
timeout-minutes: 10

strategy:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- macos-12
- macos-13
- macos-15
branch:
- master
- release-branch.go1.23
- release-branch.go1.22
- release-branch.go1.21
goroot:
- /usr/local/go
- /tmp/golang-tip
@@ -96,6 +104,12 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: false

- name: Build .tar.gz file
run: make targz-build

56 changes: 34 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
FROM golang:1.22.6
# syntax=docker/dockerfile:1

ARG GO_BRANCH


FROM --platform=$BUILDPLATFORM golang:1.23.2 AS prepare

RUN git clone https://go.googlesource.com/go /tmp/golang-tip

# make sure that following steps are not cached;
# mostly for local testing, not for GitHub Actions
ARG CACHEBUST=1
RUN echo "$CACHEBUST"

FROM golang:1.23.2

ARG GO_BRANCH
RUN test -n "$GO_BRANCH"

ENV GOLANG_VERSION=${GO_BRANCH}

RUN cd /tmp/golang-tip && \
git reset --hard && \
git clean -xdf && \
git remote prune origin && \
git checkout "$GO_BRANCH" && \
git pull
COPY --from=prepare /tmp/golang-tip /tmp/golang-tip

RUN <<EOF
set -ex

test -n "$GOLANG_VERSION"

cd /tmp/golang-tip
git reset --hard
git clean -xdf
git remote prune origin
git checkout "$GOLANG_VERSION"
git pull

# RUN cd /tmp/golang-tip/src && env GOROOT_FINAL=/usr/local/go ./all.bash
# TODO https://github.com/AlekSi/golang-tip/issues/3
RUN cd /tmp/golang-tip/src && env GOROOT_FINAL=/usr/local/go ./make.bash
cd /tmp/golang-tip/src
env GOROOT_FINAL=/usr/local/go ./make.bash

RUN cd / && \
rm -fr /usr/local/go && \
rm -fr /tmp/golang-tip/.git && \
mv -v /tmp/golang-tip /usr/local/go && \
go version
cd /
rm -fr /usr/local/go
rm -fr /tmp/golang-tip/.git
mv /tmp/golang-tip /usr/local/go
go version

# to save time to users
RUN go install -v -race std && \
go install -v std && \
go clean -cache
go clean -cache
go install -race std
go install std

EOF

LABEL org.opencontainers.image.title="Daily builds of active Go development branches"
LABEL org.opencontainers.image.title="Daily builds of active Go development branches (branch ${GO_BRANCH})"
LABEL org.opencontainers.image.url=https://github.com/AlekSi/golang-tip
LABEL org.opencontainers.image.source=https://github.com/AlekSi/golang-tip
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
GO_BRANCH ?= master
DOCKER_PLATFORM ?= linux
DOCKER_OUTPUT ?= type=docker
DOCKER_TAG ?= golang-tip:$(GO_BRANCH)

all: docker-build targz-build

@@ -13,10 +16,10 @@ docker-build:

docker buildx build \
--builder golang-tip \
--output type=docker \
--tag golang-tip:$(GO_BRANCH) \
--platform $(DOCKER_PLATFORM) \
--output $(DOCKER_OUTPUT) \
--tag $(DOCKER_TAG) \
--build-arg GO_BRANCH=$(GO_BRANCH) \
--build-arg CACHEBUST=$(shell date +%s) \
.

# run tests when limits problem is fixed
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/AlekSi/golang-tip

go 1.22
go 1.23

toolchain go1.22.6
toolchain go1.23.2

0 comments on commit 9854a2e

Please sign in to comment.