hotfix: 삭제 api 오류 수정 #91
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: CI/CD | |
on: | |
push: | |
branches: [ main, dev ] | |
# pull_request: | |
# branches: [ main, dev ] | |
env: | |
DOCKER_IMAGE: ghcr.io/${{ github.actor }}/ness-fastapi | |
VERSION: ${{ github.sha }} | |
NAME: ness-fastapi | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
env: | |
OPENAI_API_KEY: ${{secrets.OPENAI_API_KEY}} | |
CHROMA_DB_IP_ADDRESS: ${{secrets.CHROMA_DB_IP_ADDRESS}} | |
RDS_HOST: ${{ secrets.RDS_HOST }} | |
RDS_USER: ${{ secrets.RDS_USER }} | |
RDS_PASSWORD: ${{ secrets.RDS_PASSWORD }} | |
RDS_DATABASE: ${{ secrets.RDS_DATABASE }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Create .env file | |
run: | | |
echo "CHROMA_DB_IP_ADDRESS=${{ secrets.CHROMA_DB_IP_ADDRESS }}" >> .env | |
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env | |
echo "RDS_HOST=${{ secrets.RDS_HOST }}" >> .env | |
echo "RDS_USER=${{ secrets.RDS_USER }}" >> .env | |
echo "RDS_PASSWORD=${{ secrets.RDS_PASSWORD }}" >> .env | |
echo "RDS_DATABASE=${{ secrets.RDS_DATABASE }}" >> .env | |
shell: bash | |
- name: Setup docker buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Cache docker layers | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ env.VERSION }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Login to ghcr | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v2 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
push: true | |
tags: ${{ env.DOCKER_IMAGE }}:latest | |
# EC2 볼륨 16기가로 늘려서 테스트 -> 파티션 용량 조절 필요 | |
deploy: | |
needs: build | |
name: Deploy | |
runs-on: [ self-hosted, label-NESS ] | |
steps: | |
- name: Login to ghcr | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GHCR_TOKEN }} | |
- name: Create .env file | |
run: | | |
touch .env | |
echo "$DEV_ENV" > .env | |
env: | |
DEV_ENV: ${{ secrets.DEV_ENV }} | |
- name: Docker run | |
run: | | |
docker stop ${{ env.NAME }} || true | |
docker rm ${{ env.NAME }} || true | |
docker rmi -f $(docker images -aq) || true | |
docker pull ${{ env.DOCKER_IMAGE }}:latest | |
docker run -d -p 80:80 --name ${{ env.NAME }} --restart always \ | |
-e CHROMA_DB_IP_ADDRESS=${{ secrets.CHROMA_DB_IP_ADDRESS }} \ | |
-e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} \ | |
-e RDS_HOST=${{ secrets.RDS_HOST }} \ | |
-e RDS_USER=${{ secrets.RDS_USER }} \ | |
-e RDS_PASSWORD=${{ secrets.RDS_PASSWORD }} \ | |
-e RDS_DATABASE=${{ secrets.RDS_DATABASE }} \ | |
${{ env.DOCKER_IMAGE }}:latest |