Skip to content
Open

Ci/1 #60

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
168 changes: 120 additions & 48 deletions .github/workflows/dev_deploy.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,135 @@
#name: Maeummal CI/CD
#
#on:
# pull_request:
# types: [closed] # pull request 가 닫히면 즉, 머지가 됐을 때 돌아라!
# workflow_dispatch: # (2).수동 실행도 가능하도록
#
#jobs:
# build:
# runs-on: ubuntu-latest # (3).OS환경 / 우분투 기반
# if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop'
# # 머지가 되었는데, 머지가 된 대상이 'develop' 브랜치이면 돌아라!
#
# steps:
# - name: Checkout # 코드를 가져오는 것. 빌드를 할 코드를 가져오는 것. ( 이름은 본인이 지정 )
# uses: actions/checkout@v2 # (4).코드 check out
# # 리포지터리 최상단부터 체크 아웃 함
#
# - name: Set up JDK 17
# uses: actions/setup-java@v3
# with:
# java-version: 17 # (5).자바 설치
# distribution: 'adopt'
#
# - name: Grant execute permission for gradlew
# run: chmod +x ./gradlew
# shell: bash # (6).권한 부여
#
# - name: Build with Gradle
# run: ./gradlew clean build -x test # gradlew에 권한 줌
# shell: bash # (7).build 시작
#
# - name: Get current time
# uses: 1466587594/get-current-time@v2
# id: current-time
# with:
# format: YYYY-MM-DDTHH-mm-ss
# utcOffset: "+09:00" # (8).build 시점의 시간확보
#
# - name: Show Current Time
# run: echo "CurrentTime=$"
# shell: bash # (9).확보한 시간 보여주기
#
# - name: Generate deployment package # 빌드하는 과정
# run: |
# mkdir -p deploy
# cp build/libs/*.jar deploy/application.jar
# cp Procfile deploy/Procfile
# cp -r .ebextensions_dev deploy/.ebextensions
# cp -r .platform deploy/.platform
# cd deploy && zip -r deploy.zip .
#
# - name: Beanstalk Deploy
# uses: einaregilsson/beanstalk-deploy@v20
# with:
# aws_access_key: ${{ secrets.AWS_ACTION_ACCESS_KEY_ID }}
# aws_secret_key: ${{ secrets.AWS_ACTION_SECRET_ACCESS_KEY }}
# application_name: maeummal-dev # 프로젝트명
# environment_name: Maeummal-dev-env # 프로젝트명
# version_label: github-action-${{ steps.current-time.outputs.formattedTime }}
# region: ap-northeast-2
# deployment_package: deploy/deploy.zip
# wait_for_deployment: false

#name: Java CI with Gradle
#
#on:
# push:
# branches: develop
# pull_request:
# branches: develop
#
#jobs:
# build:
#
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v2
# - name: Set up JDK 11
# uses: actions/setup-java@v2
# with:
# java-version: '11'
# distribution: 'adopt'
# - name: Grant execute permission for gradlew
# run: chmod +x gradlew
# - name: Build with Gradle
# run: ./gradlew build
# - name: Docker build
# run: |
# docker login -u ${{ secrets.USERNAME }} -p ${{ secrets.PASSWORD }}
# docker build -t maeummal-cicd .
# docker tag maeummal-cicd maeummal/maeummal-cicd:${GITHUB_SHA::7}
# docker push maeummal/maeummal-cicd:${GITHUB_SHA::7}

name: Maeummal CI/CD

on:
push:
branches: [ "develop" ]
pull_request:
types: [closed] # pull request 가 닫히면 즉, 머지가 됐을 때 돌아라!
workflow_dispatch: # (2).수동 실행도 가능하도록
branches: [ "develop" ]

jobs:
build:
runs-on: ubuntu-latest # (3).OS환경 / 우분투 기반
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop'
# 머지가 되었는데, 머지가 된 대상이 'develop' 브랜치이면 돌아라!
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout # 코드를 가져오는 것. 빌드를 할 코드를 가져오는 것. ( 이름은 본인이 지정 )
uses: actions/checkout@v2 # (4).코드 check out
# 리포지터리 최상단부터 체크 아웃 함
- name: Checkout
uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v2
with:
java-version: 17 # (5).자바 설치
distribution: 'adopt'
java-version: '17'
distribution: 'temurin'

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash # (6).권한 부여
# Spring Boot 어플리케이션 Build (1)
- name: Spring Boot Build
run: ./gradlew clean build --exclude-task test

- name: Build with Gradle
run: ./gradlew clean build -x test # gradlew에 권한 줌
shell: bash # (7).build 시작
# Docker 이미지 Build (2)
- name: docker image build
run: docker build -t maeummal/maeummal-cicd .

- name: Get current time
uses: 1466587594/get-current-time@v2
id: current-time
# DockerHub Login (3)
- name: docker login
uses: docker/login-action@v2
with:
format: YYYY-MM-DDTHH-mm-ss
utcOffset: "+09:00" # (8).build 시점의 시간확보

- name: Show Current Time
run: echo "CurrentTime=$"
shell: bash # (9).확보한 시간 보여주기

- name: Generate deployment package # 빌드하는 과정
run: |
mkdir -p deploy
cp build/libs/*.jar deploy/application.jar
cp Procfile deploy/Procfile
cp -r .ebextensions_dev deploy/.ebextensions
cp -r .platform deploy/.platform
cd deploy && zip -r deploy.zip .

- name: Beanstalk Deploy
uses: einaregilsson/beanstalk-deploy@v20
with:
aws_access_key: ${{ secrets.AWS_ACTION_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_ACTION_SECRET_ACCESS_KEY }}
application_name: maeummal-dev # 프로젝트명
environment_name: Maeummal-dev-env # 프로젝트명
version_label: github-action-${{ steps.current-time.outputs.formattedTime }}
region: ap-northeast-2
deployment_package: deploy/deploy.zip
wait_for_deployment: false
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Docker Hub push (4)
- name: docker Hub push
run: docker push maeummal/maeummal-cicd
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#FROM ubuntu:latest
#LABEL authors="solor"
#
#ENTRYPOINT ["top", "-b"]

FROM openjdk:17-slim
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,10 @@ tasks.named('test') {
}
jar { // ci set
enabled = false
}

bootJar{ // 프로젝트 빌드 파일명 설정
archivesBaseName = 'maeummal'
archiveFileName = 'maeummal.jar'
archiveVersion = "0.0.0"
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class WordService {

private final UuidRepository uuidRepository;

private final WordRepository wordRepository;
private final UserAuthorizationConverter userAuthorizationConverter;
private final ChallengeService challengeService;

Expand Down
57 changes: 50 additions & 7 deletions src/main/java/com/vlc/maeummal/global/config/AmazonConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.vlc.maeummal.global.config;

/*
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
Expand All @@ -18,24 +18,26 @@ public class AmazonConfig {

private AWSCredentials awsCredentials;

@Value(("${cloud.aws.credentials.accessKey}"))
@Value("${cloud.aws.credentials.accessKey}")
private String accessKey;

@Value(("${cloud.aws.credentials.secretKey}"))
@Value("${cloud.aws.credentials.secretKey}")
private String secretKey;

@Value(("${cloud.aws.region.static}"))
@Value("${cloud.aws.region.static}")
private String region;

@Value(("${cloud.aws.s3.bucket}"))
@Value("${cloud.aws.s3.bucket}")
private String bucket;

@Value("${cloud.aws.s3.path.words}")
private String wordPath;

@PostConstruct
*/
/* @PostConstruct
public void init() {
this.awsCredentials = new BasicAWSCredentials(accessKey, secretKey); }
this.awsCredentials = new BasicAWSCredentials(accessKey, secretKey); }*//*

@Bean
public AmazonS3 amazonS3() {
AWSCredentials credentials
Expand All @@ -51,3 +53,44 @@ public AWSCredentialsProvider awsCredentialsProvider() {
return new AWSStaticCredentialsProvider(awsCredentials);
}
}
*/

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Getter
public class AmazonConfig {

@Value("${cloud.aws.credentials.accessKey}")
private String accessKey;

@Value("${cloud.aws.credentials.secretKey}")
private String secretKey;

@Value("${cloud.aws.region.static}")
private String region;

@Value("${cloud.aws.s3.bucket}")
private String bucket;

@Value("${cloud.aws.s3.path.words}")
private String wordPath;

@Bean
public AmazonS3 amazonS3() {
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
return AmazonS3ClientBuilder.standard()
.withRegion(region)
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.build();
}
}