-
Notifications
You must be signed in to change notification settings - Fork 1
54 lines (45 loc) · 1.46 KB
/
main-backend.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
47
48
49
50
51
52
53
54
name: Deploy to EC2
on:
push:
branches:
- backend-ci-cd
jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Maven
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'
- name: Create .env file
run: |
cd app/backend/src/main/resources
echo "${{ secrets.ENVIRONMENT_VARIABLES }}" > .env
- name: Build with Maven
run: |
cd app/backend
mvn clean install
- name: Build Docker image
run: |
cd app/backend
docker build -t bounswe2023group5:latest .
- name: Login to Docker Hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Push to Docker Hub
run: |
docker tag bounswe2023group5:latest unaldenizzz/bounswe2023group5:latest
docker push unaldenizzz/bounswe2023group5:latest
deploy_to_ec2:
needs: build_and_push
runs-on: ubuntu-latest
steps:
- name: Deploy to EC2
env:
PRIVATE_KEY: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
run: |
echo "$PRIVATE_KEY" > private_key.pem
chmod 600 private_key.pem
ssh -o StrictHostKeyChecking=no -i private_key.pem [email protected] 'bash /home/ubuntu/scripts/updateswe'