-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (90 loc) · 2.96 KB
/
prod-deploy.yml
File metadata and controls
104 lines (90 loc) · 2.96 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
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
96
97
98
99
100
101
102
103
104
run-name: Deploy to Librarease frontend by @${{ github.actor }}
on:
workflow_dispatch:
push:
branches:
- main
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
Build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: export secret key
run: |
echo "${{ vars.production_ENV }}" > .env
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'
# This is a separate action that sets up buildx runner
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
# Use Github action cache
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
# Create cache directory if it doesn't exist
- name: Ensure cache directory exists
run: mkdir -p /tmp/.buildx-cache
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.REPOSITORY }}
IMAGE_TAG: ${{ vars.IMAGE_TAG }}
run: |
docker buildx build \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max \
--tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \
--push \
.
# Temp fix for cache issue
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
deploy-frontend-service:
name: Deploy to Frontend Service
runs-on: ubuntu-latest
needs: Build
steps:
- name: Git Checkout
uses: actions/checkout@v2
- name: Echo Branch
run: echo running on branch ${GITHUB_REF##*/}
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.PROD_SERVER_IP }}
username: ${{ secrets.PROD_SERVER_USERNAME }}
port: ${{ secrets.PORT }}
key: ${{ secrets.PROD_SERVER_SSH_KEY }}
script: |
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/action
cd /home/ubuntu/deploy
bash deploy.sh