Skip to content

Commit e6e9602

Browse files
YuviGoldku1ik
authored andcommitted
Add docker image publish GH workflow
1 parent e7a88ea commit e6e9602

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

.github/workflows/publish.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "v*"
9+
10+
env:
11+
IMAGE_NAME: agg
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-22.04
16+
permissions:
17+
packages: write
18+
contents: read
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- name: Build image
24+
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
25+
26+
- name: Log in to registry
27+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
28+
29+
- name: Push image
30+
run: |
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+
# Strip git ref prefix from version
36+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
37+
# Strip "v" prefix from tag name
38+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
39+
# Use Docker `latest` tag convention
40+
[ "$VERSION" == "main" ] && VERSION=latest
41+
echo IMAGE_ID=$IMAGE_ID
42+
echo VERSION=$VERSION
43+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
44+
docker push $IMAGE_ID:$VERSION

0 commit comments

Comments
 (0)