mirror of https://github.com/tidwall/tile38.git
Enables cross platform building and pushing of
docker images
This commit is contained in:
parent
dbd565d361
commit
be3d48c8cb
|
@ -7,12 +7,10 @@ on:
|
||||||
branches: [master]
|
branches: [master]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
- name: Set up Go 1.x
|
- name: Set up Go 1.x
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
|
@ -26,6 +24,9 @@ jobs:
|
||||||
- name: Test
|
- name: Test
|
||||||
run: make test
|
run: make test
|
||||||
|
|
||||||
|
- name: Package
|
||||||
|
run: make package
|
||||||
|
|
||||||
- name: Docker push
|
- name: Docker push
|
||||||
env:
|
env:
|
||||||
DOCKER_LOGIN: tidwall
|
DOCKER_LOGIN: tidwall
|
||||||
|
|
11
Dockerfile
11
Dockerfile
|
@ -1,9 +1,14 @@
|
||||||
FROM alpine:3.16.2
|
FROM alpine:3.16.2
|
||||||
|
|
||||||
|
ARG VERSION
|
||||||
|
ARG TARGETOS
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
RUN apk add --no-cache ca-certificates
|
RUN apk add --no-cache ca-certificates
|
||||||
|
|
||||||
ADD tile38-server /usr/local/bin
|
ADD packages/tile38-$VERSION-$TARGETOS-$TARGETARCH/tile38-server /usr/local/bin
|
||||||
ADD tile38-cli /usr/local/bin
|
ADD packages/tile38-$VERSION-$TARGETOS-$TARGETARCH/tile38-cli /usr/local/bin
|
||||||
ADD tile38-benchmark /usr/local/bin
|
ADD packages/tile38-$VERSION-$TARGETOS-$TARGETARCH/tile38-benchmark /usr/local/bin
|
||||||
|
|
||||||
RUN addgroup -S tile38 && \
|
RUN addgroup -S tile38 && \
|
||||||
adduser -S -G tile38 tile38 && \
|
adduser -S -G tile38 tile38 && \
|
||||||
|
|
|
@ -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.
|
# DOCKER_REPO - the base repository name to push the docker build to.
|
||||||
export DOCKER_REPO=$DOCKER_USER/tile38
|
export DOCKER_REPO=$DOCKER_USER/tile38
|
||||||
|
|
||||||
|
docker images
|
||||||
|
docker inspect $DOCKER_REPO:$GIT_COMMIT_SHORT
|
||||||
|
|
||||||
if [ "$GIT_BRANCH" != "master" ]; then
|
if [ "$GIT_BRANCH" != "master" ]; then
|
||||||
echo "Not pushing, not on master"
|
echo "Not pushing, not on master"
|
||||||
elif [ "$DOCKER_USER" == "" ]; then
|
elif [ "$DOCKER_USER" == "" ]; then
|
||||||
|
@ -24,19 +27,32 @@ elif [ "$DOCKER_PASSWORD" == "" ]; then
|
||||||
echo "Not pushing, DOCKER_PASSWORD not set"
|
echo "Not pushing, DOCKER_PASSWORD not set"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
push(){
|
# setup cross platform builder
|
||||||
docker tag $DOCKER_REPO:$GIT_COMMIT_SHORT $DOCKER_REPO:$1
|
# https://github.com/tonistiigi/binfmt
|
||||||
docker push $DOCKER_REPO:$1
|
docker run --privileged --rm tonistiigi/binfmt --install all
|
||||||
echo "Pushed $DOCKER_REPO:$1"
|
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
|
# docker login
|
||||||
echo $DOCKER_PASSWORD | docker login -u $DOCKER_LOGIN --password-stdin
|
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
|
if [ "$(curl -s https://hub.docker.com/v2/repositories/$DOCKER_REPO/tags/$GIT_VERSION/ | grep "digest")" == "" ]; then
|
||||||
# push the newest tag
|
# build the docker image
|
||||||
push "$GIT_VERSION"
|
docker buildx build \
|
||||||
push "latest"
|
-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
|
fi
|
||||||
push "edge"
|
|
||||||
fi
|
fi
|
|
@ -42,5 +42,3 @@ else
|
||||||
zip -r -q $bdir.zip $bdir
|
zip -r -q $bdir.zip $bdir
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove build directory.
|
|
||||||
rm -rf $bdir
|
|
||||||
|
|
Loading…
Reference in New Issue