-
Notifications
You must be signed in to change notification settings - Fork 2
59 lines (49 loc) · 1.82 KB
/
github-actions.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
55
56
57
58
59
name: issue-tracking-system CI/CD
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Set up environment variables
run: |
echo "DB_URL=${{ secrets.DB_URL }}" >> $GITHUB_ENV
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> $GITHUB_ENV
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> $GITHUB_ENV
- name: Build with Gradle
run: ./gradlew build
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker image
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracking-system:latest .
- name: Push Docker image
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracking-system:latest
- name: Deploy to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_KEY }}
script: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/issue-tracking-system:latest
docker stop issue-tracking-system || true
docker rm issue-tracking-system || true
docker run -d -p 80:8080 --name issue-tracking-system \
-e DB_URL=${{ secrets.DB_URL }} \
-e DB_USERNAME=${{ secrets.DB_USERNAME }} \
-e DB_PASSWORD=${{ secrets.DB_PASSWORD }} \
${{ secrets.DOCKERHUB_USERNAME }}/issue-tracking-system:latest
sleep 10
docker logs issue-tracking-system