Merge pull request #682 from eelcocramer/docker-cross-platform

Enables cross platform building and pushing of docker images
This commit is contained in:
Josh Baker 2023-05-06 07:03:52 -07:00 committed by GitHub
commit cd957dcafd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 40 deletions

View File

@ -7,12 +7,10 @@ on:
branches: [master]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
@ -26,6 +24,9 @@ jobs:
- name: Test
run: make test
- name: Package
run: make package
- name: Docker push
env:
DOCKER_LOGIN: tidwall

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

@ -24,19 +24,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

View File

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