-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (108 loc) · 4.26 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: Issue 18 Workflow
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew clean build --exclude-task test
## 웹 이미지 빌드 및 도커허브에 push
- name: web docker build and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_REPO }}/mappin-server .
docker push ${{ secrets.DOCKER_REPO }}/mappin-server
docker build -t ${{ secrets.DOCKER_REPO }}/mappin-nginx -f dockerfile-nginx .
docker push ${{ secrets.DOCKER_REPO }}/mappin-nginx
- name: Install Docker on EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: |
if ! apt list --upgradable 2>/dev/null | grep -q "upgradable"; then
sudo apt update -y
fi
if ! command -v docker &> /dev/null; then
sudo apt install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker ubuntu
else
echo "Docker is already installed"
fi
if ! command -v docker-compose &> /dev/null; then
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
fi
- name: EC2 docker remove
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: |
if [ "$(sudo docker ps -aq)" ]; then
sudo docker stop $(sudo docker ps -aq)
sudo docker rm -f $(sudo docker ps -aq)
fi
if [ "$(sudo docker images -aq)" ]; then
sudo docker rmi -f $(sudo docker images -aq)
fi
- name: Copy file to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
source: ./docker-compose.yaml
target: /home/ubuntu/
- name: Create and Copy .env File to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: |
# Create .env file
echo "DB_URL=${{ secrets.DB_URL }}" > ~/.env
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> ~/.env
echo "DB_PASS=${{ secrets.DB_PASS }}" >> ~/.env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> ~/.env
echo "KAKAO_CLIENT=${{ secrets.KAKAO_CLIENT }}" >> ~/.env
echo "KAKAO_SECRET=${{ secrets.KAKAO_SECRET }}" >> ~/.env
echo "KAKAO_REST_API_KEY=${{ secrets.KAKAO_REST_API_KEY }}" >> ~/.env
echo "S3ACCESSKEY=${{ secrets.S3ACCESSKEY }}" >> ~/.env
echo "S3SECRETKEY=${{ secrets.S3SECRETKEY }}" >> ~/.env
# Copy .env file to the project directory
#cp ~/.env /home/ubuntu/.env
## docker compose up
- name: Docker Compose on EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: |
# Docker 이미지 다운로드
sudo docker pull ${{ secrets.DOCKER_REPO }}/mappin-server
sudo docker pull ${{ secrets.DOCKER_REPO }}/mappin-nginx
# Docker Compose 실행
sudo docker-compose up -d
sudo docker-compose logs -f
# 사용하지 않는 Docker 이미지 정리
sudo docker image prune -f