Code deploy #112
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Code deploy | |
on: | |
pull_request: | |
branches: [ "main" ] | |
types: [ closed ] | |
workflow_dispatch: | |
inputs: | |
logLevel: | |
description: 'Log level' | |
required: true | |
default: 'warning' | |
tags: | |
description: 'Test scenario tags' | |
jobs: | |
build: | |
# if: github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: make application-oauth.yml | |
run: | | |
cd ./src/main/resources | |
touch ./application-oauth.yml | |
echo "${{ secrets.APPLICATION_PROD }}" > ./application-oauth.yml | |
- name: make application-datasource.yaml | |
run: | | |
cd ./src/main/resources | |
touch ./application-datasource.yaml | |
echo "${{ secrets.APPLICATION_DATASOURCE }}" > ./application-datasource.yaml | |
- name: make application-cloud.yaml | |
run: | | |
cd ./src/main/resources | |
touch ./application-cloud.yaml | |
echo "${{ secrets.APPLICATION_CLOUD }}" > ./application-cloud.yaml | |
- name: make firestore.json | |
run: | | |
cd ./src/main/resources | |
touch ./firestore.json | |
echo "${{ secrets.FIRESTORE }}" > ./firestore.json | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 | |
- name: Build with Gradle Wrapper | |
run: ./gradlew build -x test | |
- name: Docker build | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -t app . | |
docker tag app ${{ secrets.DOCKER_USERNAME }}/maru:latest | |
docker push ${{ secrets.DOCKER_USERNAME }}/maru:latest | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.AWS_HOST }} # EC2 인스턴스 퍼블릭 DNS | |
username: ubuntu | |
key: ${{ secrets.AWS_ACCESS_SECRET_KEY }} # pem 키 | |
# 도커 작업 | |
script: | | |
touch ~/docker-compose.yml | |
echo "${{ secrets.DOCKER_COMPOSE }}" > ~/docker-compose.yml | |
EXCLUDE_CONTAINER_NAME="maru-rec-sys-container" | |
EXCLUDE_CONTAINER_ID=$(docker ps -qf "name=$EXCLUDE_CONTAINER_NAME") | |
CONTAINERS=$(docker ps -q) | |
for CONTAINER in $CONTAINERS; do | |
if [ "$CONTAINER" != "$EXCLUDE_CONTAINER_ID" ]; then | |
docker stop $CONTAINER | |
fi | |
done | |
docker ps -aq | grep -v $EXCLUDE_CONTAINER_ID | xargs docker rm | |
docker rmi $(docker images -q) | |
docker-compose up -d | |
docker image prune -a -f |