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

ci: deploy 파이프라인을 구성한다 #17

Merged
merged 16 commits into from
Jan 30, 2025
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
85 changes: 85 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: 🎇 Deployer

on:
push:
branches:
- 'release'

jobs:
build:
name: build and set image
runs-on: ubuntu-latest
strategy:
matrix:
kotlin-version: [ 1.9.22 ]
java-version: [ 21 ]
steps:
- name: checkout code
uses: actions/checkout@v3
with:
submodules: true

- name: Set up JDK 21 and Kotlin 1.9.22
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: ${{ matrix.java-version }}
kotlin-version: ${{ matrix.kotlin-version }}

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

- name: build server
run: ./gradlew build

- name: docker arm64 build set up - qemu
uses: docker/setup-qemu-action@v2

- name: docker arm64 build set up - buildx
uses: docker/setup-buildx-action@v2

- name: login github container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}

- name: extract version
run: echo "##[set-output name=version;]$(echo '${{ github.event.head_commit.message }}' | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')"
id: extract_version_name

- name: build and push api server
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64
push: true
tags: |
ghcr.io/nexters/misikapi/misikapi:${{ steps.extract_version_name.outputs.version }}
build-args: |
"DB_URL=${{ secrets.DB_URL }}"
"DB_USERNAME=${{ secrets.DB_USERNAME }}"
"DB_PASSWORD=${{ secrets.DB_PASSWORD }}"
"REDIS_HOST=${{ secrets.REDIS_HOST }}"
"REDIS_PORT=${{ secrets.REDIS_PORT }}"
"CLOVA_AUTHORIZATION=${{ secrets.CLOVA_AUTHORIZATION }}"

deploy:
needs: build
name: deploy
runs-on: self-hosted
steps:
- name: extract version
run: echo "##[set-output name=version;]$(echo '${{ github.event.head_commit.message }}' | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')"
id: extract_version_name

- name: run api server
run: |
sudo docker pull ghcr.io/nexters/misikapi/misikapi:${{ steps.extract_version_name.outputs.version }}
sudo docker ps -q --filter "expose=8080" | xargs sudo docker stop | xargs sudo docker rm
sudo docker run -d -p 8080:8080 --network docker-compose_misik_api_network ghcr.io/nexters/misikapi/misikapi:${{ steps.extract_version_name.outputs.version }}
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM openjdk:21-jdk

ARG DB_URL
ARG DB_USERNAME
ARG DB_PASSWORD
ARG REDIS_HOST
ARG REDIS_PORT
ARG CLOVA_AUTHORIZATION

ARG JAR_FILE=./build/libs/*.jar
COPY ${JAR_FILE} misik-api.jar

ENV db_url=${DB_URL} \
db_username=${DB_USERNAME} \
db_password=${DB_PASSWORD} \
redis_host=${REDIS_HOST} \
redis_port=${REDIS_PORT} \
clova_authorization=${CLOVA_AUTHORIZATION}

ENTRYPOINT java -jar misik-api.jar \
--spring.datasource.url=${db_url} \
--spring.datasource.username=${db_username} \
--spring.datasource.password=${db_password} \
--netx.host=${redis_host} \
--netx.port=${redis_port} \
--me.misik.chatbot.clova.authorization=${clova_authorization}
Loading