From d64ce82d34b66051842d0c9f0b445b7fa0725f28 Mon Sep 17 00:00:00 2001 From: jinyongp Date: Mon, 23 Oct 2023 22:18:23 +0900 Subject: [PATCH] =?UTF-8?q?ci:=20docker=20=EC=9D=BC=EB=B0=98=20=EB=AA=85?= =?UTF-8?q?=EB=A0=B9=EC=96=B4=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 042a49e..4793960 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -28,6 +28,7 @@ jobs: - name: Create .env file with Secrets uses: SpicyPizza/create-envfile@v2.0 with: + envkey_DATABASE_URL: mysql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE} envkey_DB_DATABASE: ${{ secrets.DB_DATABASE }} envkey_DB_PASSWORD: ${{ secrets.DB_PASSWORD }} envkey_DB_HOST: ${{ secrets.DB_HOST }} @@ -47,15 +48,6 @@ jobs: push: true tags: ${{ secrets.DK_USERNAME }}/${{ secrets.DK_IMAGE }}:latest - - name: Send docker-compose.yml, .env to EC2 - uses: appleboy/scp-action@v0.1.4 - with: - host: ${{ secrets.EC2_HOST }} - username: ubuntu - key: ${{ secrets.EC2_KEY }} - source: docker-compose.yml,.env - target: /home/ubuntu - - name: Deploy Docker to EC2 uses: appleboy/ssh-action@v1.0.0 with: @@ -64,10 +56,17 @@ jobs: key: ${{ secrets.EC2_KEY }} script_stop: true script: | - mv .env /tmp - export $(cat /tmp/.env | xargs) - sudo docker compose pull - sudo docker compose up -d - sudo docker container prune -f - sudo docker image prune -f - rm -f docker-compose.yml /tmp/.env + sudo docker pull mysql:8.1.0 + sudo docker pull ${{ secrets.DK_USERNAME }}/${{ secrets.DK_IMAGE }}:latest + sudo docker rm -f ${{ secrets.DK_IMAGE }} || true + sudo docker rm -f ${{ secrets.DK_IMAGE }}-db || true + sudo docker network rm api-network || true + sudo docker network create api-network + sudo docker run --network api-network --name ${{ secrets.DK_IMAGE }}-db \ + -e MYSQL_DATABASE=${{ secrets.DB_DATABASE }} -e MYSQL_ROOT_PASSWORD=${{ secrets.DB_PASSWORD }} -e TZ=${{ secrets.TZ }} \ + -v mysql-data:/var/lib/mysql -p ${{ secrets.DB_PORT }}:3306 -d mysql:8.1.0 --default-authentication-plugin=mysql_native_password + sudo docker run --network api-network --add-host host.docker.internal:host-gateway --name ${{ secrets.DK_IMAGE }} \ + --link ${{ secrets.DK_IMAGE }}-db:db -p ${{ secrets.PORT }}:${{ secrets.PORT }} \ + -d ${{ secrets.DK_USERNAME }}/${{ secrets.DK_IMAGE }}:latest /home/bun/app/wait-for-db.sh + sudo docker container prune -f || true + sudo docker image prune -f || true