Skip to content

Commit

Permalink
setting: 서버 환경 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
D0ri123 committed Oct 2, 2023
1 parent 95df138 commit 24adbbd
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 49 deletions.
70 changes: 36 additions & 34 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
name: backend-deploy
name: Java CI with Gradle

on:
push:
branches:
- main
- develop
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]

permissions:
contents: read

env:
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4.0.0
- name: checkout working directory
uses: actions/checkout@v3

- name: set up Java
uses: actions/setup-java@v3.12.0
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: "11"
distribution: "zulu"

- name: Grant execute permission for gradlew
run: chmod +x gradlew
shell: bash
java-version: '11'
distribution: 'temurin'

- name: Build with Gradle
run: ./gradlew bootjar
shell: bash

- name: Make zip file
run: zip -r ./$GITHUB_SHA.zip .
shell: bash
run: ./gradlew bootJar

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
- name: Login to DockerHub
uses: docker/login-action@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip

- name: Code Deploy
run: aws deploy create-deployment --application-name bbok-deploy --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name bbok-code-deploy --s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=$GITHUB_SHA.zip
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: web image build and push
env:
NAME: ${{ secrets.DOCKER_USERNAME }}
REPO: ${{ secrets.DOCKER_REPO }}
run: |
docker build -t $NAME/$REPO .
docker push $NAME/$REPO
- 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_USERNAME }}/server-web
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/server-nginx
docker-compose up -d
docker image prune -f
14 changes: 0 additions & 14 deletions appspec.yml

This file was deleted.

4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ plugins {
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

jar {
enabled = false
}

group = 'com.dnd'
version = '0.0.1-SNAPSHOT'

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

web:
container_name: web
image: leeseolhui/server-web
expose:
- 8080
ports:
- 8080:8080

nginx:
container_name: nginx
image: leeseolhui/server-nginx
ports:
- 80:80
depends_on:
- web
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} server.jar
ENTRYPOINT ["java","-jar","/server.jar"]
2 changes: 2 additions & 0 deletions dockerfile-nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM nginx
COPY ./nginx/conf.d/nginx.conf /etc/nginx/conf.d
21 changes: 21 additions & 0 deletions nginx/conf.d/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
server {
listen 80;
server_name bbok.o-r.kr;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
server_name bbok.o-r.kr;

ssl_certificate /etc/letsencrypt/live/bbok.o-r.kr/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/bbok.o-r.kr/privkey.pem;

location / {
proxy_pass http://web:8080;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
1 change: 0 additions & 1 deletion test.txt

This file was deleted.

0 comments on commit 24adbbd

Please sign in to comment.