Skip to content

Commit

Permalink
Merge pull request #86 from MEME-UMC/ci/#80
Browse files Browse the repository at this point in the history
[CI] CI/CD 구현
  • Loading branch information
daeun084 authored Feb 3, 2024
2 parents b897d7a + 8fac087 commit a87904e
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 2 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: main Workflow

on:
push:
branches:
- develop
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'

- name: Set .yml for main
run: |
mkdir -p src/main/resources
echo "${{ secrets.MAIN_DATABASE_YML }}" | base64 --decode > src/main/resources/application.yml
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew clean build --exclude-task test

## 웹 이미지 빌드 및 도커허브에 push
- name: web docker build and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_REPO }}/meme-service .
docker push ${{ secrets.DOCKER_REPO }}/meme-service
- name: EC2 docker remove
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ec2-user
key: ${{ secrets.KEY }}
script: |
if [ "$(sudo docker ps -aq)" ]; then
sudo docker stop $(sudo docker ps -aq)
sudo docker rm -f $(sudo docker ps -aq)
fi
if [ "$(sudo docker images -aq)" ]; then
sudo docker rmi -f $(sudo docker images -aq)
fi
- name: Copy file to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ec2-user
key: ${{ secrets.KEY }}
source: ./docker-compose.yaml
target: /home/ec2-user/

- name: Create and Copy .env File to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ec2-user
key: ${{ secrets.KEY }}
script: |
# Create .env file
echo "DB_URL=${{ secrets.DB_URL }}" > ~/.env
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> ~/.env
echo "DB_PASS=${{ secrets.DB_PASS }}" >> ~/.env
# Copy .env file to the project directory
#cp ~/.env /home/ec2-user/.env
## docker compose up
- name: Docker Compose on EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ec2-user
key: ${{ secrets.KEY }}
script: |
# Docker 이미지 다운로드
sudo docker pull ${{ secrets.DOCKER_REPO }}/meme-service
# Docker Compose 실행
sudo docker-compose up -d
sudo docker-compose logs -f
# 사용하지 않는 Docker 이미지 정리
sudo docker image prune -f
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:17-alpine
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
18 changes: 18 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3'
services:
web:
container_name: service
image: sunwupark/meme-service
expose:
- 8080
ports:
- "8080:8080"

auth:
container_name: auth
image: sunwupark/meme-auth
expose:
- 8081
ports:
- "8081:8081"
depends_on: web
Empty file modified gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Artist {
private String profileImg;

@Column(nullable = false, length = 500)
private String introduction = "안녕하세요! 저는 ___입니다!";
private String introduction;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class ReviewResponseDto {
private List<ReviewImgDto> reviewImgDtoList;

public static ReviewResponseDto from(Review review){

List<ReviewImgDto> reviewImgDtoList = review.getReviewImgList()
.stream()
.map(reviewImg -> new ReviewImgDto(reviewImg.getReviewImgId(), reviewImg.getSrc(), false))
Expand Down

0 comments on commit a87904e

Please sign in to comment.