-
Notifications
You must be signed in to change notification settings - Fork 2
97 lines (84 loc) · 3.13 KB
/
cd.yml
File metadata and controls
97 lines (84 loc) · 3.13 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
name: CD Pipeline
on:
push:
branches: [ main ]
jobs:
cd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true
- name: Create buildx builder
run: |
docker buildx create --use --name mybuilder
docker buildx inspect --bootstrap
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build & Push Dependency Cache
run: |
docker buildx build \
--builder mybuilder \
--platform linux/amd64 \
--push \
--file Dockerfile \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/haru-app:dependency-cache \
--target dependencies \
--cache-to type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/haru-app:dependency-cache,mode=max \
.
- name: Build & Push Final App Image (Production)
run: |
docker buildx build \
--builder mybuilder \
--platform linux/amd64 \
--push \
--file Dockerfile \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/haru-app:latest \
--build-arg DEPENDENCY_IMAGE=${{ secrets.DOCKERHUB_USERNAME }}/haru-app:dependency-cache \
--cache-from type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/haru-app:dependency-cache \
.
- name: Create application-secret.yml
run: |
mkdir -p ./temp_secret
echo "${{ secrets.APPLICATION_SECRET }}" > ./temp_secret/application-secret.yml
shell: bash
- name: Copy application-secret.yml to EC2
uses: appleboy/scp-action@v0.1.3
with:
username: ubuntu
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_SSH_KEY }}
source: ./temp_secret/application-secret.yml
target: /home/ubuntu/secret/
- name: Copy docker-compose.yml
uses: appleboy/scp-action@v0.1.3
with:
username: ubuntu
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_SSH_KEY }}
source: ./docker-compose.yml
target: /home/ubuntu/cicd/spring/
- name: Upload deploy.sh to EC2
uses: appleboy/scp-action@v0.1.3
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
source: ./deploy.sh
target: /home/ubuntu/cicd/spring
- name: SSH and Deploy
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/haru-app:latest
sudo chmod +x /home/ubuntu/cicd/spring/deploy.sh
sudo /home/ubuntu/cicd/spring/deploy.sh