-
Notifications
You must be signed in to change notification settings - Fork 1
46 lines (40 loc) · 1.49 KB
/
cicd.yml
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
name: CI/CD using GitHub Actions & Docker
on:
push:
branches:
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
run: |
cd paperplane
./gradlew build -x test
- name: Docker Build & Push
run: |
cd paperplane
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_TOKEN }}
docker build -t ${{ secrets.DOCKER_USERNAME }}/paperplane-prod:latest .
docker push ${{ secrets.DOCKER_USERNAME }}/paperplane-prod:latest
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script: |
echo "Pulling the latest Docker image on EC2"
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_TOKEN }}
docker pull ${{ secrets.DOCKER_USERNAME }}/paperplane-prod:latest
echo "Stopping existing container (if running)"
docker stop paperplane || true && docker rm paperplane || true
echo "Starting a new container"
docker run -d --name paperplane -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/paperplane-prod:latest