-
Notifications
You must be signed in to change notification settings - Fork 1
95 lines (77 loc) · 2.67 KB
/
backend.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
93
94
95
name: Backend CI and CD
on:
push:
branches:
- main
paths:
- .github/**
- backend/**
pull_request:
paths:
- .github/**
- backend/**
env:
REGISTRY: ghcr.io
IMAGE_NAME: backend
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'
- name: Run unit tests
run: |
cd ./backend && go test ./... -v -race -cover
- name: Provide image name and version
run: |
IMAGE_ID=$(echo $REGISTRY/${{ github.repository_owner }}/$IMAGE_NAME | tr '[A-Z]' '[a-z]')
IMAGE_VERSION=${{ github.sha }}
echo "IMAGE_ID=$IMAGE_ID" >> "$GITHUB_ENV"
echo "IMAGE_VERSION=$IMAGE_VERSION" >> "$GITHUB_ENV"
- name: Build image
run: |
cd ./backend && docker build . --file Dockerfile --target production --tag $IMAGE_ID:$IMAGE_VERSION --tag $IMAGE_ID:latest
cd:
runs-on: ubuntu-latest
# This job will be invoked only on default branch
if: ${{ always() && format('refs/heads/{0}', github.event.repository.default_branch) == github.ref }}
permissions:
packages: write
contents: read
needs:
- ci
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Provide image name and version
run: |
IMAGE_ID=$(echo $REGISTRY/${{ github.repository_owner }}/$IMAGE_NAME | tr '[A-Z]' '[a-z]')
IMAGE_VERSION=${{ github.sha }}
echo "IMAGE_ID=$IMAGE_ID" >> "$GITHUB_ENV"
echo "IMAGE_VERSION=$IMAGE_VERSION" >> "$GITHUB_ENV"
- name: Build image
run: |
cd ./backend && docker build . --file Dockerfile --target production --tag $IMAGE_ID:$IMAGE_VERSION --tag $IMAGE_ID:latest
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image
run: |
docker push $IMAGE_ID:$IMAGE_VERSION
docker push $IMAGE_ID:latest
- uses: actions/setup-node@v3
with:
node-version: "18"
- name: deploy to production
env:
LIARA_TOKEN: ${{ secrets.LIARA_API_TOKEN }}
LIARA_BACKEND_APP_NAME: ${{secrets.LIARA_BACKEND_APP_NAME}}
run: |
IMAGE_NAME=backend
IMAGE_ID=$REGISTRY/${{ github.repository_owner }}/$IMAGE_NAME
VERSION=latest
npm i -g @liara/cli@7
liara deploy --image $IMAGE_ID:$VERSION --platform=docker --port="80" --app="$LIARA_BACKEND_APP_NAME" --api-token="$LIARA_TOKEN" --detach