diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0fdaea26..c9f05171 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index b9cf53c4..243ea715 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 && \ diff --git a/scripts/docker-push.sh b/scripts/docker-push.sh index 5d4c049a..52187f58 100755 --- a/scripts/docker-push.sh +++ b/scripts/docker-push.sh @@ -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 \ No newline at end of file +fi diff --git a/scripts/package.sh b/scripts/package.sh index 6bdbf7f2..8951b5fd 100755 --- a/scripts/package.sh +++ b/scripts/package.sh @@ -42,5 +42,3 @@ else zip -r -q $bdir.zip $bdir fi -# Remove build directory. -rm -rf $bdir