From a909b9c77408544f6932ae278488f66b9149f9db Mon Sep 17 00:00:00 2001 From: haen-su Date: Wed, 12 Jul 2023 23:52:19 +0900 Subject: [PATCH 1/6] =?UTF-8?q?feat:=20Dockerfile=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e9e6a93 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM openjdk:11 +ARG JAR_FILE=build/libs/*.jar +COPY ${JAR_FILE} app.jar +ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file From e3a2f4d09d63f54871123291d550e59861f2f7e9 Mon Sep 17 00:00:00 2001 From: haen-su Date: Thu, 13 Jul 2023 00:15:05 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20nignx=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/nginx/Dockerfile | 2 ++ config/nginx/nginx.conf | 17 +++++++++++++++++ docker-compose.yml | 20 ++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 config/nginx/Dockerfile create mode 100644 config/nginx/nginx.conf create mode 100644 docker-compose.yml diff --git a/config/nginx/Dockerfile b/config/nginx/Dockerfile new file mode 100644 index 0000000..ebd0a6f --- /dev/null +++ b/config/nginx/Dockerfile @@ -0,0 +1,2 @@ +FROM nginx +COPY ./nginx.conf /etc/nginx/conf.d/default.conf \ No newline at end of file diff --git a/config/nginx/nginx.conf b/config/nginx/nginx.conf new file mode 100644 index 0000000..cba95bc --- /dev/null +++ b/config/nginx/nginx.conf @@ -0,0 +1,17 @@ +server { + + listen 80; + + location / { + proxy_pass http://dansup-web:8080; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_redirect off; + } + + if ($http_x_forwarded_proto != 'https') { + return 301 https://$host$request_uri; + } + +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d7d71b2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3' +services: + + web: + container_name: dansup-web + image: dansup-web + expose: + - 8080 + ports: + - 8080:8080 + tty: true + + nginx: + container_name: dansup-nginx + image: dansup-nginx + ports: + - 80:80 + depends_on: + - dansup_web + restart: always \ No newline at end of file From f8d8dba3c8b7b90141a703abc731dbd7329dbee6 Mon Sep 17 00:00:00 2001 From: haen-su Date: Thu, 13 Jul 2023 00:28:45 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20docker-compose=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d7d71b2..378d062 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,17 +2,19 @@ version: '3' services: web: - container_name: dansup-web - image: dansup-web + container_name: web + image: haensu/dansup-web expose: - 8080 ports: - 8080:8080 - tty: true nginx: - container_name: dansup-nginx - image: dansup-nginx + container_name: nginx + image: haensu/dansup-nginx + build: + dockerfile: Dockerfile + context: ./config/nginx ports: - 80:80 depends_on: From 563846a02d6a8a3804a3a35f383f586ee306b42b Mon Sep 17 00:00:00 2001 From: haen-su Date: Thu, 13 Jul 2023 01:11:43 +0900 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20deploy.yml=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 56 ++++++++++++++++++++++++++++++++++++ build.gradle | 4 +++ 2 files changed, 60 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..1cd4bd0 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,56 @@ +name: Deploy to EC2 + +on: + push: + branches: [ "develop" ] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - name: Make application-database.yml + run: | + cd ./src/main/resources + touch ./application-database.yml + echo "${{ secrets.DATABASE }}" >> ./application-database.yml + shell: bash + + - name: Build with Gradle + run: | + chmod +x ./gradlew + ./gradlew clean build -x test + + - name: Docker Build and Push + run: | + docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + docker build -t ${{ secrets.DOCKER_REPO }}/dansup-web . + docker push ${{ secrets.DOCKER_REPO }}/dansup-web + docker build -t ${{ secrets.DOCKER_REPO }}/dansup-nginx . + docker push ${{ secrets.DOCKER_REPO }}/dansup-nginx + + ## Docker Compose Up + - name: executing remote ssh commands using password + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ubuntu + key: ${{ secrets.KEY }} + script: | + sudo docker rm -f $(docker ps -qa) + sudo docker pull ${{ secrets.DOCKER_REPO }}/dansup-web + sudo docker pull ${{ secrets.DOCKER_REPO }}/dansup-nginx + docker-compose up -d + docker image prune -f + diff --git a/build.gradle b/build.gradle index 65df1fe..c11fb27 100644 --- a/build.gradle +++ b/build.gradle @@ -45,3 +45,7 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + +jar { + enabled = false +} From 4717b2cebe6e30f8441db922a2313272c640018b Mon Sep 17 00:00:00 2001 From: haen-su Date: Thu, 13 Jul 2023 02:00:15 +0900 Subject: [PATCH 5/6] =?UTF-8?q?feat:=20docker=20repo=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=80=EC=88=98=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 21 +++++++++++++-------- .gitignore | 7 ++++--- docker-compose.yml | 6 +++--- src/main/resources/application.yml | 4 ++++ 4 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 src/main/resources/application.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1cd4bd0..eb866c6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -20,11 +20,16 @@ jobs: java-version: '11' distribution: 'temurin' + - name: Create Env File + run: | + touch .env + echo "${{ secrets.ENV_VARS }}" >> .env + - name: Make application-database.yml run: | cd ./src/main/resources touch ./application-database.yml - echo "${{ secrets.DATABASE }}" >> ./application-database.yml + echo "${{ secrets.DATABASE }}" >> ./application-db.yml shell: bash - name: Build with Gradle @@ -34,11 +39,11 @@ jobs: - name: Docker Build and Push run: | - docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - docker build -t ${{ secrets.DOCKER_REPO }}/dansup-web . - docker push ${{ secrets.DOCKER_REPO }}/dansup-web - docker build -t ${{ secrets.DOCKER_REPO }}/dansup-nginx . - docker push ${{ secrets.DOCKER_REPO }}/dansup-nginx + sudo docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} + sudo docker build -t ${{ secrets.DOCKER_REPO }}/dansup-web . + sudo docker push ${{ secrets.DOCKER_REPO }}/dansup-web + sudo docker build -t ${{ secrets.DOCKER_REPO }}/dansup-nginx . + sudo docker push ${{ secrets.DOCKER_REPO }}/dansup-nginx ## Docker Compose Up - name: executing remote ssh commands using password @@ -51,6 +56,6 @@ jobs: sudo docker rm -f $(docker ps -qa) sudo docker pull ${{ secrets.DOCKER_REPO }}/dansup-web sudo docker pull ${{ secrets.DOCKER_REPO }}/dansup-nginx - docker-compose up -d - docker image prune -f + sudo docker-compose up -d + sudo docker image prune -f diff --git a/.gitignore b/.gitignore index 9b09060..0e96ad4 100644 --- a/.gitignore +++ b/.gitignore @@ -41,7 +41,8 @@ out/ ### properties ### /src/main/resources/application.properties -/src/main/resources/application-prod.properties -/src/main/resources/application.yml -/src/main/resources/application-prod.yml +/src/main/resources/application-db.yml +/src/main/resources/application-oauth.yml +### 환경변수 ### +.env \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 378d062..2eed548 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: web: container_name: web - image: haensu/dansup-web + image: ${DOCKER_REPO}/dansup-web expose: - 8080 ports: @@ -11,12 +11,12 @@ services: nginx: container_name: nginx - image: haensu/dansup-nginx + image: ${DOCKER_REPO}/dansup-nginx build: dockerfile: Dockerfile context: ./config/nginx ports: - 80:80 depends_on: - - dansup_web + - web restart: always \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..52de898 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,4 @@ +spring: + profiles: + include: + - db, oauth \ No newline at end of file From 4613c586fa3ddffa771ec084d61ec696f8c3962c Mon Sep 17 00:00:00 2001 From: haen-su Date: Thu, 13 Jul 2023 02:05:55 +0900 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20application.yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 52de898..da8c17a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,5 @@ spring: profiles: include: - - db, oauth \ No newline at end of file + - db + - oauth \ No newline at end of file