-
Notifications
You must be signed in to change notification settings - Fork 4
92 lines (82 loc) · 2.94 KB
/
build-and-push-docker.yaml
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: 🐳 Build and Push Docker Images
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
build-backend:
name: 🛠️ Build and Push
runs-on: ubuntu-latest
steps:
- name: 🚀 Checkout Code
uses: actions/checkout@v4
# Get version from version.yaml
- name: 📁 Get version
run: |
echo "VERSION=$(cat version.yaml | sed -n 's/version: //p')" >> $GITHUB_ENV
echo $VERSION
# Set build tags based on branch
- name: 🏗️ Set Build tags
run: |
if [ $GITHUB_REF = 'refs/heads/main' ]; then
echo "IMAGE_TAGS=$VERSION" >> $GITHUB_ENV
else
echo "IMAGE_TAGS=rc-$VERSION-$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
fi
- name: 🛠️ Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Login to GitHub Container Registry
- name: 🔐 Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.TOKEN }}
# Login to Docker Hub
- name: 🔐 Login to Docker Hub
if: github.ref == 'refs/heads/main'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 📦 Build and Push Image to GHCR (PR)
if: github.event_name == 'pull_request'
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ghcr.io/kek-sec/gopherdrop:${{ env.IMAGE_TAGS }}
annotations: |
org.opencontainers.image.description=GopherDrop, a secure one-time secret sharing service
build-args: |
VERSION=${{ env.VERSION }}
labels: |
org.opencontainers.image.source=https://github.com/kek-sec/gopherdrop
cache-from: type=registry,ref=ghcr.io/kek-sec/gopherdrop:latest
cache-to: type=registry,ref=ghcr.io/kek-sec/gopherdrop:latest
- name: 📦 Build and Push Image to GHCR and Docker Hub (Main)
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: |
ghcr.io/kek-sec/gopherdrop:${{ env.IMAGE_TAGS }}
petrakisg/gopherdrop:${{ env.IMAGE_TAGS }}
annotations: |
org.opencontainers.image.description=GopherDrop, a secure one-time secret sharing service
build-args: |
VERSION=${{ env.VERSION }}
labels: |
org.opencontainers.image.source=https://github.com/kek-sec/gopherdrop
cache-from: type=registry,ref=ghcr.io/kek-sec/gopherdrop:latest
cache-to: type=registry,ref=ghcr.io/kek-sec/gopherdrop:latest