Skip to content

Commit 5394d43

Browse files
committed
👷 Build and publish image on GH Actions
1 parent b7efa61 commit 5394d43

File tree

1 file changed

+47
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)