Skip to content
This repository was archived by the owner on Aug 13, 2022. It is now read-only.

[#109] AWS를 활용한 서버 배포 #110

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:11-jre-slim
ARG JAR_FILE=./build/libs/FoodEats-0.0.1-SNAPSHOT.jar
ADD ${JAR_FILE} foodeats.jar
ENTRYPOINT ["java","-jar","/foodeats.jar"]
49 changes: 49 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
pipeline {
agent any
options {
timeout(time: 1, unit: 'HOURS')
}

environment {
SOURCECODE_JENKINS_CREDENTIAL_ID = 'jenkins-github-wh'
SOURCE_CODE_URL = 'https://github.com/f-lab-edu/FoodEats.git'
RELEASE_BRANCH = 'main'
}

stages {
stage('Init') {
steps {
echo 'clear'
sh 'docker stop $(docker ps -aq)'
sh 'docker rm $(docker ps -aq)'
sh 'docker rmi $(docker images -q)'
deleteDir()
}
}

stage('clone') {
steps {
git url: "$SOURCE_CODE_URL",
branch: "$RELEASE_BRANCH",
credentialsId: "$SOURCECODE_JENKINS_CREDENTIAL_ID"
sh "ls -al"
}
}

stage('dockerizing') {
steps {
sh "pwd"
sh "chmod +x ./gradlew"
sh "./gradlew build --stacktrace"

sh "docker build -t foodeats ."
}
}

stage('deploy') {
steps {
sh "docker-compose up --build -d"
}
}
Comment on lines +14 to +47
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 이 순서로 배포를 하게 되면, git에서 클론 받고, gradle 빌드하고, dockerize하고, 다시 docker-compose up이 완료될 때 까지 서비스가 동작하지 않겠네요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 부분 생각치 못했습니다..
해당 문제점에 대한 해결책을 생각해보고 은수님과 스터디시간에 얘기를 나눈 뒤 수정할 수 있도록 하겠습니다!

Copy link
Collaborator Author

@yusok7 yusok7 Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

멘토님께서 피드백을 주셨듯이,
현재 방법은 배포 시 반드시 서비스를 중단해야하므로 무중단배포가 이뤄지지 않습니다.

이를 해결하기 위해 확실하지는 않지만 2가지 방법을 현재 알아보고 있습니다.
1. nginx를 활용한 방식
2. github actions를 활용한 방식
좀 더 알아보고 내일 멘토링 시간에 들어갈 수 있도록 하겠습니다!

}
}
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3"

services:
nginx:
image: nginx:1.21.0
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
ports:
- "80:80"
depends_on:
- foodeats1
- foodeats2

foodeats1:
image: foodeats
ports:
- "8080:8080"

foodeats2:
image: foodeats
ports:
- "8081:8080"

redis:
image: redis:6.2.4
ports:
- "6379:6379"


11 changes: 11 additions & 0 deletions nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
upstream foodeats {
server foodeats1:8080;
server foodeats2:8080;
}

server {
listen 80;
location / {
proxy_pass http://foodeats;
}
}