-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (72 loc) · 3.57 KB
/
build-and-deploy.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
name: build and deploy
on:
push:
branches:
- main
workflow_dispatch:
env:
REGISTRY_URL: ghcr.io
REGISTRY_USERNAME: azamatkomaev
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
IMAGE_TAG: ${{ github.sha }}
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PORT: ${{ secrets.SSH_PORT }}
S3_ENDPOINT_URL: ${{ secrets.S3_ENDPOINT_URL }}
S3_REGION: ${{ secrets.S3_REGION }}
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login with Github Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY_URL }}
username: ${{ env.REGISTRY_USERNAME }}
password: ${{ env.REGISTRY_PASSWORD }}
- name: Add custom builder
run: |
docker buildx create \
--name container-builder \
--driver docker-container \
--bootstrap --use
- name: Build & Publish backend to Github Container registry
run: |
docker buildx build --platform linux/amd64,linux/arm64 --push ./backend \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_backend:latest \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_backend:$IMAGE_TAG \
--cache-to type=s3,endpoint_url=$S3_ENDPOINT_URL,region=$S3_REGION,bucket=$BUCKET_NAME,name=calendar_backend,access_key_id=$ACCESS_KEY,secret_access_key=$SECRET_KEY \
--cache-from type=s3,endpoint_url=$S3_ENDPOINT_URL,region=$S3_REGION,bucket=$BUCKET_NAME,name=calendar_backend,access_key_id=$ACCESS_KEY,secret_access_key=$SECRET_KEY
- name: Build & Publish frontend to Github Container registry
run: |
docker buildx build --platform linux/amd64,linux/arm64 --push ./frontend \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_frontend:latest \
--tag $REGISTRY_URL/$REGISTRY_USERNAME/yet_another_calendar_frontend:$IMAGE_TAG \
--cache-to type=s3,endpoint_url=$S3_ENDPOINT_URL,region=$S3_REGION,bucket=$BUCKET_NAME,name=calendar_frontend,access_key_id=$ACCESS_KEY,secret_access_key=$SECRET_KEY \
--cache-from type=s3,endpoint_url=$S3_ENDPOINT_URL,region=$S3_REGION,bucket=$BUCKET_NAME,name=calendar_frontend,access_key_id=$ACCESS_KEY,secret_access_key=$SECRET_KEY
deploy:
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v4
- run: 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- name: Set up SSH private key.
run: eval "$(ssh-agent -s)"
- run: mkdir -p ~/.ssh
- run: ssh-keyscan -p $SSH_PORT $SSH_HOST >> ~/.ssh/known_hosts
- run: ssh-agent -a $SSH_AUTH_SOCK > /dev/null
- run: ssh-add - <<< "${{ secrets.SSH_KEY }}"
- name: Add image tag to .version file
run: |
echo $IMAGE_TAG > .version
scp -P 666 .version $SSH_USER@$SSH_HOST:~/YetAnotherCalendar/.version
- name: Update docker compose
run: |
ssh $SSH_USER@$SSH_HOST -p $SSH_PORT "cd YetAnotherCalendar/ && git pull origin main &&
YET_ANOTHER_CALENDAR_VERSION=$(cat .version) docker compose -f docker-compose.prod.yaml pull &&
YET_ANOTHER_CALENDAR_VERSION=$(cat .version) docker compose -f docker-compose.prod.yaml up -d"