Enables cross platform building and pushing of

docker images
This commit is contained in:
Eelco Cramer 2023-05-03 11:02:40 +02:00
parent dbd565d361
commit be3d48c8cb
No known key found for this signature in database
GPG Key ID: 92BE398A20135E17
4 changed files with 56 additions and 36 deletions

View File

@ -2,33 +2,34 @@ name: Go
on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.19
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.19
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Test
run: make test
- name: Test
run: make test
- name: Package
run: make package
- name: Docker push
env:
DOCKER_LOGIN: tidwall
DOCKER_USER: tile38
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: ./scripts/docker-push.sh
- name: Docker push
env:
DOCKER_LOGIN: tidwall
DOCKER_USER: tile38
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: ./scripts/docker-push.sh

View File

@ -1,9 +1,14 @@
FROM alpine:3.16.2
ARG VERSION
ARG TARGETOS
ARG TARGETARCH
RUN apk add --no-cache ca-certificates
ADD tile38-server /usr/local/bin
ADD tile38-cli /usr/local/bin
ADD tile38-benchmark /usr/local/bin
ADD packages/tile38-$VERSION-$TARGETOS-$TARGETARCH/tile38-server /usr/local/bin
ADD packages/tile38-$VERSION-$TARGETOS-$TARGETARCH/tile38-cli /usr/local/bin
ADD packages/tile38-$VERSION-$TARGETOS-$TARGETARCH/tile38-benchmark /usr/local/bin
RUN addgroup -S tile38 && \
adduser -S -G tile38 tile38 && \

View File

@ -12,6 +12,9 @@ export GIT_COMMIT_SHORT=$(git rev-parse --short HEAD)
# DOCKER_REPO - the base repository name to push the docker build to.
export DOCKER_REPO=$DOCKER_USER/tile38
docker images
docker inspect $DOCKER_REPO:$GIT_COMMIT_SHORT
if [ "$GIT_BRANCH" != "master" ]; then
echo "Not pushing, not on master"
elif [ "$DOCKER_USER" == "" ]; then
@ -24,19 +27,32 @@ elif [ "$DOCKER_PASSWORD" == "" ]; then
echo "Not pushing, DOCKER_PASSWORD not set"
exit 1
else
push(){
docker tag $DOCKER_REPO:$GIT_COMMIT_SHORT $DOCKER_REPO:$1
docker push $DOCKER_REPO:$1
echo "Pushed $DOCKER_REPO:$1"
}
# setup cross platform builder
# https://github.com/tonistiigi/binfmt
docker run --privileged --rm tonistiigi/binfmt --install all
docker buildx create --name multiarch --platform linux/amd64,linux/amd64/v2,linux/amd64/v3,linux/arm64,linux/386,linux/arm/v7 --use default
# docker login
echo $DOCKER_PASSWORD | docker login -u $DOCKER_LOGIN --password-stdin
# build the docker image
docker build -f Dockerfile -t $DOCKER_REPO:$GIT_COMMIT_SHORT .
if [ "$(curl -s https://hub.docker.com/v2/repositories/$DOCKER_REPO/tags/$GIT_VERSION/ | grep "digest")" == "" ]; then
# push the newest tag
push "$GIT_VERSION"
push "latest"
# build the docker image
docker buildx build \
-f Dockerfile \
--platform linux/arm64,linux/amd64 \
--build-arg VERSION=$GIT_VERSION \
--tag $DOCKER_REPO:$GIT_VERSION \
--tag $DOCKER_REPO:latest \
--tag $DOCKER_REPO:edge \
--push \
.
else
# build the docker image
docker buildx build \
-f Dockerfile \
--platform linux/arm64,linux/amd64 \
--build-arg VERSION=$GIT_VERSION \
--tag $DOCKER_REPO:edge \
--push \
.
fi
push "edge"
fi
fi

View File

@ -42,5 +42,3 @@ else
zip -r -q $bdir.zip $bdir
fi
# Remove build directory.
rm -rf $bdir