Skip to content

Commit 23a9b7f

Browse files
committed
ci(publish): add github workflow - docker-publish
1 parent 6ca9158 commit 23a9b7f

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Docker
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
push:
7+
# Publish `main` as Docker `latest` image.
8+
branches:
9+
- main
10+
11+
# Publish `v1.2.3` tags as releases.
12+
tags:
13+
- v*
14+
15+
env:
16+
IMAGE_NAME: default
17+
18+
jobs:
19+
push:
20+
21+
runs-on: ubuntu-latest
22+
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }}
23+
24+
steps:
25+
- uses: actions/checkout@v2
26+
27+
- name: Build image
28+
run: docker build . --file Dockerfile --tag $IMAGE_NAME --cache-from ghcr.io/${{ github.repository }}:latest
29+
30+
- name: Login to GitHub Container Registry
31+
uses: docker/login-action@v1
32+
with:
33+
registry: ghcr.io
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Push image
38+
run: |
39+
IMAGE_ID=ghcr.io/${{ github.repository }}
40+
# Change all uppercase to lowercase
41+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
42+
# Strip git ref prefix from version
43+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
44+
# Strip "v" prefix from tag name
45+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
46+
# Use Docker `latest` tag convention
47+
[ "$VERSION" == "main" ] && VERSION=latest
48+
echo IMAGE_ID=$IMAGE_ID
49+
echo VERSION=$VERSION
50+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
51+
docker push $IMAGE_ID:$VERSION

0 commit comments

Comments
 (0)