mirror of
https://github.com/miaowware/qrm2.git
synced 2024-11-22 15:58:40 -05:00
83 lines
2.5 KiB
YAML
83 lines
2.5 KiB
YAML
# vim: ts=2 sw=2:
|
|
|
|
name: Docker Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
# Publish `master` as Docker `dev` image.
|
|
branches:
|
|
- master
|
|
# Publish `v*` tags as x.x.x images and as `latest`.
|
|
tags:
|
|
- v*
|
|
|
|
jobs:
|
|
docker:
|
|
name: Build and push docker images
|
|
runs-on: ubuntu-20.04
|
|
permissions:
|
|
packages: write
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v2
|
|
with:
|
|
ref: ${{ github.ref }}
|
|
|
|
- name: Write ref to file
|
|
run: git rev-list -n 1 $GITHUB_REF > ./git_commit
|
|
|
|
- name: Build image
|
|
id: build_image
|
|
run: |
|
|
IMAGE_ID=${GITHUB_REPOSITORY,,}
|
|
IMAGE_NAME=${IMAGE_ID#*/}
|
|
echo "image_id=$IMAGE_ID" >> $GITHUB_ENV
|
|
echo "image_name=$IMAGE_NAME" >> $GITHUB_ENV
|
|
docker build . --file Dockerfile -t $IMAGE_NAME
|
|
|
|
- name: Login to Github Container Registry
|
|
uses: docker/login-action@v1
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Tag image
|
|
id: tag_image
|
|
run: |
|
|
IMAGE_NAME=${{ env.image_name }}
|
|
IMAGE_ID=ghcr.io/${{ env.image_id }}
|
|
echo IMAGE_ID=$IMAGE_ID
|
|
echo "image_id=$IMAGE_ID" >> $GITHUB_ENV
|
|
|
|
# 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//')
|
|
# if version is master, set version to dev
|
|
[[ "$VERSION" == "master" ]] && VERSION=dev
|
|
echo VERSION=$VERSION
|
|
echo "version=$VERSION" >> $GITHUB_ENV
|
|
|
|
# tag dev or x.x.x
|
|
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
|
|
# tag latest if not a dev release
|
|
[[ "$VERSION" != "dev" ]] && docker tag $IMAGE_NAME $IMAGE_ID:latest || true
|
|
|
|
- name: Push images to registry
|
|
run: |
|
|
VERSION=${{ env.version }}
|
|
IMAGE_ID=${{ env.image_id }}
|
|
|
|
[[ "$VERSION" != "dev" ]] && docker push $IMAGE_ID:latest || true
|
|
docker push $IMAGE_ID:$VERSION
|
|
|
|
- name: Deploy official images
|
|
id: deploy_images
|
|
uses: satak/webrequest-action@v1
|
|
with:
|
|
url: ${{ secrets.DEPLOY_URL }}
|
|
method: POST
|
|
headers: '{"Authentication": "Token ${{ secrets.DEPLOY_TOKEN }}"}'
|
|
payload: '{"version": "${{ env.version }}"}'
|