From d86e897ba6b65597c76f271877e34ff9572643e8 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 29 Jul 2022 14:30:16 +0100 Subject: [PATCH] Rework dockerhub builds (#22026) * WIP * Attempt to wire up dockerhub building in GHA * Fix issue with mime types * Skip linux/arm, Cypress only installs on 64-bit * Update dockerhub.yaml * Update comment --- .github/workflows/dockerhub.yaml | 57 ++++++++++++++++++++++++++++++++ Dockerfile | 3 -- scripts/docker-link-repos.sh | 8 ++--- scripts/docker-package.sh | 21 +++++------- 4 files changed, 70 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/dockerhub.yaml diff --git a/.github/workflows/dockerhub.yaml b/.github/workflows/dockerhub.yaml new file mode 100644 index 0000000000..076fbb7842 --- /dev/null +++ b/.github/workflows/dockerhub.yaml @@ -0,0 +1,57 @@ +name: Dockerhub +on: + workflow_dispatch: { } + push: + tags: [ v* ] + schedule: + # This job can take a while, and we have usage limits, so just publish develop only twice a day + - cron: '0 7/12 * * *' +concurrency: ${{ github.ref_name }} +jobs: + buildx: + name: Docker Buildx + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # needed for docker-package to be able to calculate the version + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + install: true + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: | + vectorim/element-web + tags: | + type=ref,event=branch + type=ref,event=tag + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Update repo description + uses: peter-evans/dockerhub-description@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + repository: vectorim/element-web diff --git a/Dockerfile b/Dockerfile index d33e1d8458..6e888088a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,9 +27,6 @@ FROM nginx:alpine COPY --from=builder /src/webapp /app -# Insert wasm type into Nginx mime.types file so they load correctly. -RUN sed -i '3i\ \ \ \ application/wasm wasm\;' /etc/nginx/mime.types - # Override default nginx config COPY /nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf diff --git a/scripts/docker-link-repos.sh b/scripts/docker-link-repos.sh index cf824d87ad..0c45137caf 100644 --- a/scripts/docker-link-repos.sh +++ b/scripts/docker-link-repos.sh @@ -5,7 +5,7 @@ set -ex # Automatically link to develop if we're building develop, but only if the caller # hasn't asked us to build something else BRANCH=$(git rev-parse --abbrev-ref HEAD) -if [ $USE_CUSTOM_SDKS == false ] && [ $BRANCH == 'develop' ] +if [[ $USE_CUSTOM_SDKS == false ]] && [[ $BRANCH == 'develop' ]] then echo "using develop dependencies for react-sdk and js-sdk" USE_CUSTOM_SDKS=true @@ -13,21 +13,21 @@ then REACT_SDK_BRANCH='develop' fi -if [ $USE_CUSTOM_SDKS == false ] +if [[ $USE_CUSTOM_SDKS == false ]] then echo "skipping react-sdk and js-sdk installs: USE_CUSTOM_SDKS is false" exit 0 fi echo "Linking js-sdk" -git clone --depth 1 --branch $JS_SDK_BRANCH $JS_SDK_REPO js-sdk +git clone --depth 1 --branch $JS_SDK_BRANCH "$JS_SDK_REPO" js-sdk cd js-sdk yarn link yarn --network-timeout=100000 install cd ../ echo "Linking react-sdk" -git clone --depth 1 --branch $REACT_SDK_BRANCH $REACT_SDK_REPO react-sdk +git clone --depth 1 --branch $REACT_SDK_BRANCH "$REACT_SDK_REPO" react-sdk cd react-sdk yarn link yarn link matrix-js-sdk diff --git a/scripts/docker-package.sh b/scripts/docker-package.sh index f1bb99abf4..3beb01151c 100755 --- a/scripts/docker-package.sh +++ b/scripts/docker-package.sh @@ -1,21 +1,18 @@ -#!/bin/sh +#!/bin/bash set -ex -TAG=$(git describe --tags) BRANCH=$(git rev-parse --abbrev-ref HEAD) -DIST_VERSION=$TAG +DIST_VERSION=$(git describe --abbrev=0 --tags) -# If the branch comes out as HEAD then we're probably checked out to a tag, so if the thing is *not* -# coming out as HEAD then we're on a branch. When we're on a branch, we want to resolve ourselves to -# a few SHAs rather than a version. -# Docker Hub doesn't always check out the tag and sometimes checks out the branch, so we should look -# for an appropriately tagged branch as well (heads/v1.2.3). -if [[ $BRANCH != HEAD && ! $BRANCH =~ heads/v.+ ]] +DIR=$(dirname "$0") + +# If we're not using custom SDKs and on a branch other than master, generate a version akin go develop.element.io +if [[ $USE_CUSTOM_SDKS == false ]] && [[ $BRANCH != 'master' ]] then - DIST_VERSION=`$(dirname $0)/get-version-from-git.sh` + DIST_VERSION=$("$DIR"/get-version-from-git.sh) fi -DIST_VERSION=`$(dirname $0)/normalize-version.sh ${DIST_VERSION}` +DIST_VERSION=$("$DIR"/normalize-version.sh "$DIST_VERSION") VERSION=$DIST_VERSION yarn build -echo $DIST_VERSION > /src/webapp/version +echo "$DIST_VERSION" > /src/webapp/version