Improved docker CI
This commit is contained in:
@@ -4,6 +4,10 @@
|
||||
**/dist
|
||||
**/docs
|
||||
|
||||
**/.github
|
||||
**/.husky
|
||||
**/.vscode
|
||||
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
docker-compose.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 }}
|
||||
|
||||
Reference in New Issue
Block a user