-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (37 loc) · 1.68 KB
/
docker-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: Build and Push Docker image
on:
push:
branches:
- main # This will trigger the workflow on push to the main branch.
tags:
- v*
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin
- name: Build and tag Docker image
run: |
docker build -t ${{ secrets.DOCKER_HUB_USERNAME }}/pg-backup:${{ github.sha }} .
# 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//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo VERSION=$VERSION
docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/pg-backup:${{ github.sha }} ${{ secrets.DOCKER_HUB_USERNAME }}/pg-backup:latest
- name: Push Docker image to Docker Hub
run: |
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/pg-backup:${{ github.sha }}
# 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//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo VERSION=$VERSION
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/pg-backup:$VERSION