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

build: github actions #28 #56

Merged
merged 6 commits into from
Jan 22, 2024
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
123 changes: 123 additions & 0 deletions .github/workflows/ci-cd-flow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: ci/cd

on:
push:
branches:
- develop_back
pull_request:
branches:
- develop_back

jobs:
formatting:
name: formatting
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
- uses: actions/checkout@v3
- uses: axel-op/googlejavaformat-action@v3
with:
args: "--replace"
skip-commit: true

deploy-core:
name: core application deploy
needs: formatting
if: ${{ github.event_name == 'push' }}
runs-on: ubuntu-latest

defaults:
run:
working-directory: ./backend/core

permissions:
id-token: write
contents: read

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.CI_PAT }}

- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'liberica'
cache: gradle

- name: grant execute permission for gradlew
run: chmod +x ./gradlew

- name: build gradle
run: ./gradlew clean build

- name: Configure AWS credentials
seokho-1116 marked this conversation as resolved.
Show resolved Hide resolved
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Set up Docker Buildx
seokho-1116 marked this conversation as resolved.
Show resolved Hide resolved
uses: docker/setup-buildx-action@v3

- name: Set up QEMU
seokho-1116 marked this conversation as resolved.
Show resolved Hide resolved
uses: docker/setup-qemu-action@v3

- name: Login to Amazon ECR
seokho-1116 marked this conversation as resolved.
Show resolved Hide resolved
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Extract metadata (tags, labels) for Docker
seokho-1116 marked this conversation as resolved.
Show resolved Hide resolved
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ steps.login-ecr.outputs.registry }}/${{ secrets.AWS_ECR_REPOSITORY_NAME }}
tags: |
type=raw,value=latest

- name: Build and push
seokho-1116 marked this conversation as resolved.
Show resolved Hide resolved
uses: docker/build-push-action@v5
with:
context: ./backend/core
platforms: linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
provenance: false

- name: Get Github action IP
id: ip
uses: haythem/[email protected]

- name: Add Github Actions IP to Security group
seokho-1116 marked this conversation as resolved.
Show resolved Hide resolved
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_EC2_CORE_SG_ID }} --group-name ${{secrets.AWS_EC2_CORE_SG_NAME}} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32

- name: Connect ec2 and Run Docker Container
seokho-1116 marked this conversation as resolved.
Show resolved Hide resolved
uses: appleboy/[email protected]
env:
AWS_ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
with:
host: ${{ secrets.SSH_CORE_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_CORE_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
docker ps -q --filter "name=core" | xargs -r docker stop
docker ps -aq --filter "name=core" | xargs -r docker rm
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username ${{ secrets.AWS_DOCKER_USER }} --password-stdin ${{ secrets.AWS_USER_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
docker pull ${{ steps.meta.outputs.tags }}
docker run -d -p 8080:8080 --name core --network test_backend ${{ steps.meta.outputs.tags }}

- name: Remove Github Actions IP from security group
if: always()
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_EC2_CORE_SG_ID }} --group-name ${{secrets.AWS_EC2_CORE_SG_NAME}} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
seokho-1116 marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 0 additions & 19 deletions .github/workflows/google-java-format.yml

This file was deleted.

4 changes: 2 additions & 2 deletions backend/core/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:17-jre as build
FROM bellsoft/liberica-openjdk-alpine:17 as build
WORKDIR /workspace/app

# Copy Gradle wrapper and other necessary files
Expand All @@ -8,7 +8,7 @@ COPY build/libs/ .
RUN mkdir -p target/extracted
RUN java -Djarmode=layertools -jar *.jar extract --destination target/extracted

FROM eclipse-temurin:17-jre
FROM bellsoft/liberica-openjdk-alpine:17
VOLUME /tmp
ARG EXTRACTED=/workspace/app/target/extracted

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public record ErrorResponse(
String message,

@Schema(description = "에러 리스트 ex) 필드 에러들")
List<Error> errors
List<Error> result
) {

public static ErrorResponse create(final ErrorCode errorCode) {
Expand Down