-
Notifications
You must be signed in to change notification settings - Fork 0
52 lines (43 loc) · 1.48 KB
/
deploy.yml
File metadata and controls
52 lines (43 loc) · 1.48 KB
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
name: Build and Push to GHCR
on:
push:
branches:
- main
release:
types: [published]
env:
SHORT_SHA: ${{ github.sha }}
IMAGE_NAME: ${{ github.repository_owner }}/devsprint-backend
IMAGE_TAG: ${{ github.ref_type == 'tag' && github.ref || contains(github.event.head_commit.message, 'latest') && 'latest' || 'dev' }}
jobs:
push-ghcr:
if: contains(github.event.head_commit.message, 'BUILD') || github.event_name == 'release'
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go 1.22.x
uses: actions/setup-go@v4
with:
go-version: "1.22.x"
- name: Install Go dependencies
run: go mod download
- name: 🔑 Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: 🏗️ Build and push
run: |
if [[ $IMAGE_TAG == *"refs/tags/"* ]]; then
IMAGE_TAG=$(echo $IMAGE_TAG | sed 's/refs\/tags\///')
export IMAGE_TAG
fi
echo "==>> IMAGE_TAG: $IMAGE_TAG"
docker build -t ghcr.io/${{ env.IMAGE_NAME }}:$IMAGE_TAG -t ghcr.io/${{ env.IMAGE_NAME }}:${{ env.SHORT_SHA }} .
docker push ghcr.io/${{ env.IMAGE_NAME }}:${{ env.SHORT_SHA }}
docker push ghcr.io/${{ env.IMAGE_NAME }}:$IMAGE_TAG