Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/deploy #35

Merged
merged 6 commits into from
Jul 12, 2023
Merged
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
61 changes: 61 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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: 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-db.yml
shell: bash

- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew clean build -x test

- name: Docker Build and Push
run: |
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
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
sudo docker-compose up -d
sudo docker image prune -f

7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:11
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}

jar {
enabled = false
}
2 changes: 2 additions & 0 deletions config/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM nginx
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
17 changes: 17 additions & 0 deletions config/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
}

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

web:
container_name: web
image: ${DOCKER_REPO}/dansup-web
expose:
- 8080
ports:
- 8080:8080

nginx:
container_name: nginx
image: ${DOCKER_REPO}/dansup-nginx
build:
dockerfile: Dockerfile
context: ./config/nginx
ports:
- 80:80
depends_on:
- web
restart: always
5 changes: 5 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
spring:
profiles:
include:
- db
- oauth