-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (61 loc) ยท 2.22 KB
/
docker.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: FitPet_A CI/CD
on:
push:
branches:
- develop
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: develop
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y openjdk-17-jdk
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build -x test
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker Image
run: |
# Build Docker image
echo "Building Docker image..."
docker build --no-cache -t ${{ secrets.DOCKER_USERNAME }}/fitpet-a:latest .
- name: Push Docker Image
run: |
IMAGE_NAME=${{ secrets.DOCKER_USERNAME }}/fitpet-a:latest
# Push Docker image to Docker Hub
echo "Pushing Docker image to Docker Hub..."
docker push ${{ secrets.DOCKER_USERNAME }}/fitpet-a:latest
- name: Deploy EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: |
echo "Stopping and removing existing Docker container fitpet-container (if exists)..."
sudo docker stop fitpet-container || true
sudo docker rm fitpet-container || true
echo "Starting new Docker container fitpet-container..."
sudo docker run -d -p 8080:8080 --name fitpet-container \
-e DB_USERNAME=${{ secrets.DB_USERNAME }} \
-e DB_PASSWORD=${{ secrets.DB_PASSWORD }} \
-e ACCESS_TOKEN_EXP=${{ secrets.ACCESS_TOKEN_EXP }} \
-e REFRESH_TOKEN_EXP=${{ secrets.REFRESH_TOKEN_EXP }} \
${{ secrets.DOCKER_USERNAME }}/fitpet-a:latest
echo "Pruning unused Docker objects to free up space..."
sudo docker system prune -a --volumes -f