Skip to content

Commit 9600524

Browse files
authored
Create cd.yml
1 parent 4eaac01 commit 9600524

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

.github/workflows/cd.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: CI/CD using github actions & docker
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
push_to_registry:
13+
name: Push to aws container registry
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Set up JDK 17
20+
uses: actions/setup-java@v3
21+
with:
22+
java-version: '17'
23+
distribution: 'corretto'
24+
25+
- name: make application-prod.yml
26+
if: contains(github.ref, 'develop') || contains(github.ref, 'main')
27+
run: |
28+
cd ./src/main/resources
29+
touch ./application-prod.yml
30+
echo "${{ secrets.YML_PROD }}" > ./application-prod.yml
31+
shell: bash
32+
33+
- name: Grant execute permission for gradlew
34+
run: chmod +x gradlew
35+
36+
- name: Build with Gradle
37+
env:
38+
SPRING_PROFILES_ACTIVE: prod
39+
run: ./gradlew clean build --stacktrace
40+
shell: bash
41+
42+
- name: Docker build & push to prod
43+
if: contains(github.ref, 'develop') || contains(github.ref, 'main')
44+
run: |
45+
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
46+
docker build -t kodaero-f ./Dockerfile .
47+
docker tag kodaero:latest ${{ secrets.DOCKER_USER }}/kodaero:latest
48+
docker push ${{ secrets.DOCKER_USER }}/kodaero:latest
49+
50+
51+
pull_from_registry:
52+
name: Connect server ssh and pull from container registry
53+
needs: push_to_registry
54+
runs-on: ubuntu-latest
55+
steps:
56+
- name: Get Github action IP
57+
id: ip
58+
uses: haythem/public-ip@v1.2
59+
60+
- name: Deploy to prod
61+
if: contains(github.ref, 'develop') || contains(github.ref, 'main')
62+
uses: appleboy/ssh-action@master
63+
with:
64+
host: ${{ secrets.HOST_NAME }}
65+
username: ${{ secrets.USER_NAME }}
66+
password: ${{ secrets.USER_PASSWORD }}
67+
port: ${{ secrets.PORT }}
68+
script: |
69+
docker pull ${{ secrets.DOCKER_USER }}/kodaero:latest
70+
chmod +x ./deploy.sh
71+
./deploy.sh prod
72+
docker image prune -f

0 commit comments

Comments
 (0)