Skip to content

Merge pull request #111 from Kusitms-29th-ASAP/feature/tranlate/menu #71

Merge pull request #111 from Kusitms-29th-ASAP/feature/tranlate/menu

Merge pull request #111 from Kusitms-29th-ASAP/feature/tranlate/menu #71

Workflow file for this run

name: dev deployment
on:
push:
branches:
- develop
jobs:
application_build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: java setting
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: gradle setting
run: |
chmod +x gradlew
./gradlew build \
--build-cache \
--project-cache-dir=$HOME/.gradle/caches/project \
--gradle-user-home=$HOME/.gradle/caches/global \
--project-dir="./"
- name: upload artifact
uses: actions/upload-artifact@v2
with:
name: application
path: build/libs/*.jar
push_to_docker_hub:
needs: application_build
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.generate_version.outputs.new_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: application
path: build/libs
- name: Generate Version
id: generate_version
run: |
current_date=$(date -d "9 hours" +%Y-%m-%d)
current_date_short_year=$(date -d "9 hours" +%y-%m-%d)
runs_this_month=$(curl -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/actions/runs?event=push&status=success&per_page=1&created=cats+created:<=$current_date"\
| jq '.total_count')
echo "new version is $current_date_short_year.$runs_this_month"
echo "new_version=$current_date_short_year.$runs_this_month" >> "$GITHUB_OUTPUT"
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: ${{ secrets.DOCKER_REGISTRY }}
- name: Docker build
env:
VERSION: ${{ steps.generate_version.outputs.new_version }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
run: |
docker build -f .deploy/Dockerfile -t $DOCKER_REGISTRY/$IMAGE_NAME:$VERSION .
docker tag $DOCKER_REGISTRY/$IMAGE_NAME:$VERSION $DOCKER_REGISTRY/$IMAGE_NAME:latest
docker push $DOCKER_REGISTRY/$IMAGE_NAME:$VERSION
docker push $DOCKER_REGISTRY/$IMAGE_NAME:latest
config_environment:
runs-on: ubuntu-latest
steps:
- name: config environment
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.OCI_HOST }}
username: ${{ secrets.OCI_USERNAME }}
key: ${{ secrets.OCI_SSH_KEY }}
script: |
sudo rm -rf .env
touch .env
echo "RDB_HOST=${{secrets.RDB_HOST}}" >> .env
echo "RDB_PORT=${{secrets.RDB_PORT}}" >> .env
echo "RDB_SCHEMA=${{secrets.RDB_SCHEMA}}" >> .env
echo "RDB_USER=${{secrets.RDB_USER}}" >> .env
echo "RDB_PASSWORD=${{secrets.RDB_PASSWORD}}" >> .env
echo "MONGO_HOST=${{secrets.MONGO_HOST}}" >> .env
echo "MONGO_DB=${{secrets.MONGO_DB}}" >> .env
echo "MONGO_USER=${{secrets.MONGO_USER}}" >> .env
echo "MONGO_PASSWORD=${{secrets.MONGO_PASSWORD}}" >> .env
echo "JWT_SECRET=${{secrets.JWT_SECRET}}" >> .env
echo "DOCKER_REGISTRY=${{secrets.DOCKER_REGISTRY}}" >> .env
echo "IMAGE_NAME=${{secrets.IMAGE_NAME}}" >> .env
echo "SEOUL_OPEN_API_KEY=${{secrets.SEOUL_OPEN_API_KEY}}" >> .env
echo "NEIS_OPEN_API_KEY=${{secrets.NEIS_OPEN_API_KEY}}" >> .env
echo "OPENAI_API_KEY=${{secrets.OPENAI_API_KEY}}" >> .env
echo "NCP_OCR_API_KEY=${{secrets.NCP_OCR_API_KEY}}" >> .env
run_application:
runs-on: ubuntu-latest
needs: [ push_to_docker_hub, config_environment ]
steps:
- name: Run Docker container
uses: appleboy/ssh-action@master
env:
VERSION: ${{ needs.push_to_docker_hub.outputs.new_version }}
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
with:
host: ${{ secrets.OCI_HOST }}
username: ${{ secrets.OCI_USERNAME }}
key: ${{ secrets.OCI_SSH_KEY }}
envs: VERSION, DOCKER_REGISTRY, DOCKER_USERNAME, DOCKER_PASSWORD, IMAGE_NAME
script: |
echo "new application version is $VERSION"
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY
docker pull $DOCKER_REGISTRY/$IMAGE_NAME:latest
docker stop $IMAGE_NAME || true
docker rm $IMAGE_NAME || true
docker compose up -d
docker image prune -f