mirror of
https://github.com/miaowware/qrm2.git
synced 2024-11-21 15:41:51 -05:00
.github/workflows/docker.yml: use metadata action, run on PRs
This commit is contained in:
parent
86da8d135a
commit
444687bd12
85
.github/workflows/docker.yml
vendored
85
.github/workflows/docker.yml
vendored
@ -3,6 +3,10 @@
|
|||||||
name: Docker Build and Deploy
|
name: Docker Build and Deploy
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
push:
|
push:
|
||||||
# Publish `master` as Docker `dev` image.
|
# Publish `master` as Docker `dev` image.
|
||||||
branches:
|
branches:
|
||||||
@ -11,29 +15,43 @@ on:
|
|||||||
tags:
|
tags:
|
||||||
- v*
|
- v*
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
docker:
|
docker:
|
||||||
name: Build and push docker images
|
name: Build and push docker images
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
packages: write
|
packages: write
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: classabbyamp/treeless-checkout-action@v1
|
||||||
with:
|
|
||||||
ref: ${{ github.ref }}
|
|
||||||
|
|
||||||
- name: Write ref to file
|
- name: Write ref to file
|
||||||
|
if: ${{ github.event_name != 'pull_request' }}
|
||||||
run: git rev-list -n 1 $GITHUB_REF > ./git_commit
|
run: git rev-list -n 1 $GITHUB_REF > ./git_commit
|
||||||
|
|
||||||
- name: Build image
|
- name: Docker metadata
|
||||||
id: build_image
|
id: meta
|
||||||
run: |
|
uses: docker/metadata-action@v4
|
||||||
IMAGE_ID=${GITHUB_REPOSITORY,,}
|
with:
|
||||||
IMAGE_NAME=${IMAGE_ID#*/}
|
images: |
|
||||||
echo "image_id=$IMAGE_ID" >> $GITHUB_ENV
|
ghcr.io/${{ github.repository }}
|
||||||
echo "image_name=$IMAGE_NAME" >> $GITHUB_ENV
|
tags: |
|
||||||
docker build . --file Dockerfile -t $IMAGE_NAME
|
type=sha,prefix=
|
||||||
|
type=raw,value=dev,enable={{is_default_branch}}
|
||||||
|
type=raw,event=tag,value=latest,enable={{is_default_branch}}
|
||||||
|
type=ref,event=tag,prefix=,enable={{is_default_branch}},priority=1000
|
||||||
|
flavor: latest=false
|
||||||
|
labels: |
|
||||||
|
org.opencontainers.image.authors=classabbyamp and 0x5c
|
||||||
|
org.opencontainers.image.url=https://github.com/miaowware/qrm2
|
||||||
|
org.opencontainers.image.source=https://github.com/${{ github.repository }}
|
||||||
|
org.opencontainers.image.vendor=miaowware
|
||||||
|
org.opencontainers.image.title=qrm2
|
||||||
|
org.opencontainers.image.description=Discord bot with ham radio functions
|
||||||
|
|
||||||
- name: Login to Github Container Registry
|
- name: Login to Github Container Registry
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@v1
|
||||||
@ -42,41 +60,10 @@ jobs:
|
|||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Tag image
|
- name: Build and push
|
||||||
id: tag_image
|
uses: docker/build-push-action@v5
|
||||||
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:
|
with:
|
||||||
url: ${{ secrets.DEPLOY_URL }}
|
context: .
|
||||||
method: POST
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
headers: '{"Authentication": "Token ${{ secrets.DEPLOY_TOKEN }}"}'
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
payload: '{"version": "${{ env.version }}"}'
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
Loading…
Reference in New Issue
Block a user