|
| 1 | +name: docker-build-push |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'main' |
| 7 | + tags: |
| 8 | + - '*' |
| 9 | + |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - 'main' |
| 13 | + |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +env: |
| 17 | + IMAGE_NAME: "gitlab-monitor" |
| 18 | + |
| 19 | +jobs: |
| 20 | + docker: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v2 |
| 26 | + |
| 27 | + - name: Prepare |
| 28 | + id: prep |
| 29 | + run: | |
| 30 | + BASE_DIR=. |
| 31 | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME |
| 32 | +
|
| 33 | + # Change all uppercase to lowercase |
| 34 | + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') |
| 35 | +
|
| 36 | + # Strip git ref prefix from version |
| 37 | + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') |
| 38 | +
|
| 39 | + # Strip "v" prefix from tag name |
| 40 | + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') |
| 41 | +
|
| 42 | + # Use Docker `latest` tag convention |
| 43 | + [ "$VERSION" == "main" ] && VERSION=latest |
| 44 | +
|
| 45 | + VERSION=$VERSION |
| 46 | + IMAGE_ID=$IMAGE_ID |
| 47 | + echo ::set-output name=version::${VERSION} |
| 48 | + echo ::set-output name=image_id::${IMAGE_ID} |
| 49 | + echo ::set-output name=base_dir::${BASE_DIR} |
| 50 | +
|
| 51 | + - name: Set up QEMU |
| 52 | + uses: docker/setup-qemu-action@v1 |
| 53 | + with: |
| 54 | + platforms: all |
| 55 | + |
| 56 | + - name: Set up Docker Buildx |
| 57 | + id: buildx |
| 58 | + uses: docker/setup-buildx-action@v1 |
| 59 | + with: |
| 60 | + install: true |
| 61 | + version: latest |
| 62 | + |
| 63 | + - name: Log into registry |
| 64 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
| 65 | + |
| 66 | + - name: Build and Push |
| 67 | + uses: docker/build-push-action@v2 |
| 68 | + with: |
| 69 | + build-args: VERSION=${{ steps.prep.outputs.version }} |
| 70 | + context: ${{ steps.prep.outputs.base_dir }}/ |
| 71 | + file: ${{ steps.prep.outputs.base_dir }}/Dockerfile |
| 72 | + platforms: linux/amd64,linux/arm64 |
| 73 | + push: true |
| 74 | + tags: | |
| 75 | + ${{ steps.prep.outputs.image_id }}:${{ steps.prep.outputs.version }} |
0 commit comments