Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use multi-arch Docker images #93

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 36 additions & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ on:

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

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

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

Expand All @@ -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
Expand All @@ -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

Expand Down
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

Expand All @@ -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
Expand Down
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
Loading