From 7db761fba7c6a13cf0b25fe886ea0df8a0534f27 Mon Sep 17 00:00:00 2001 From: Max Stanley Date: Tue, 21 Nov 2023 21:59:03 +0000 Subject: [PATCH] Improved docker CI --- .dockerignore | 4 ++ .github/workflows/docker-publish.yml | 94 ++++++++++++++-------------- 2 files changed, 52 insertions(+), 46 deletions(-) diff --git a/.dockerignore b/.dockerignore index 7624b2ae..dd59c3f5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,6 +4,10 @@ **/dist **/docs +**/.github +**/.husky +**/.vscode + Dockerfile .dockerignore docker-compose.yml \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index d57fc48a..1a086f1a 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -17,53 +17,55 @@ on: - develop env: - IMAGE_NAME: mermaid-live-editor + IMAGE_BASE: ghcr.io/${{ github.repository }} jobs: - test: + docker: runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Run tests - run: | - docker build . --file Dockerfile - - push: - # Ensure test job passes before pushing image. - needs: test - - runs-on: ubuntu-latest - if: github.event_name == 'push' - - steps: - - uses: actions/checkout@v3 - - - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME - - - name: Log into registry - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - - # Strip git ref prefix from version - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - - # Strip "v" prefix from tag name - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - - # Use Docker `latest` tag convention - [ "$VERSION" == "master" ] && VERSION=latest - - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - name: Login to GitHub Container Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/metadata-action@v5 + if: github.ref_type == 'tag' + id: meta + with: + images: ${IMAGE_BASE} + # this will generate tags in the following format: + # latest + # 1.2.3 + tags: | + type=raw,value=latest + type=semver,pattern={{version}} + - uses: docker/build-push-action@v5 + if: github.ref_type == 'tag' + with: + context: . + target: mermaid + push: ${{ github.event_name != 'pull_request' }} + pull: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + - uses: docker/metadata-action@v5 + if: github.ref_type == 'branch' + id: meta-nightly + with: + images: ${IMAGE_BASE} + tags: | + type=raw,value=nightly + - uses: docker/build-push-action@v5 + if: github.ref_type == 'branch' + with: + context: . + target: mermaid + push: ${{ github.event_name != 'pull_request' }} + pull: true + tags: ${{ steps.meta-nightly.outputs.tags }} + labels: ${{ steps.meta-nightly.outputs.labels }}