From d89ee9dc3a60ee8d3ba40b422d3becb162a936bb Mon Sep 17 00:00:00 2001 From: mhmdksh Date: Fri, 21 Jun 2024 18:15:54 +0400 Subject: [PATCH] Added CI for rpgf3, staging, production, changed docker-compose --- .github/workflows/production-deploy.yml | 25 +++++++++++ .../workflows/{ci.yml => rpgf3-deploy.yml} | 22 +++++---- .github/workflows/staging-deploy.yml | 25 +++++++++++ .github/workflows/test.yml | 45 ------------------- docker-compose.yml | 28 +++--------- 5 files changed, 65 insertions(+), 80 deletions(-) create mode 100644 .github/workflows/production-deploy.yml rename .github/workflows/{ci.yml => rpgf3-deploy.yml} (68%) create mode 100644 .github/workflows/staging-deploy.yml delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/production-deploy.yml b/.github/workflows/production-deploy.yml new file mode 100644 index 0000000..65bbda3 --- /dev/null +++ b/.github/workflows/production-deploy.yml @@ -0,0 +1,25 @@ +name: production-deploy-pipeline + +on: + push: + branches: + - master + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: SSH and Redeploy Production + uses: appleboy/ssh-action@v1.0.0 + with: + host: ${{ secrets.PROD_HOST }} + username: ${{ secrets.PROD_USERNAME }} + key: ${{ secrets.PROD_PRIVATE_KEY }} + port: ${{ secrets.SSH_PORT }} + script: | + cd rpgf4-pw-backend + docker-compose down -v + docker image prune -a --force + git checkout master + git pull origin master + docker-compose up -d --build diff --git a/.github/workflows/ci.yml b/.github/workflows/rpgf3-deploy.yml similarity index 68% rename from .github/workflows/ci.yml rename to .github/workflows/rpgf3-deploy.yml index 705ee8e..35e088b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/rpgf3-deploy.yml @@ -1,9 +1,9 @@ -name: deploy-pipeline +name: rpgf3-deploy-pipeline on: push: branches: - - master + - rpgf3 jobs: deploy: @@ -18,12 +18,11 @@ jobs: port: ${{ secrets.SSH_PORT }} script: | cd pw-backend - docker-compose down - git checkout master + docker-compose down -v docker image prune -a --force - git pull origin master - docker-compose build - docker-compose up -d + git checkout rpgf3 + git pull origin rpgf3 + docker-compose up -d --build - name: SSH and Redeploy Staging uses: appleboy/ssh-action@v1.0.0 @@ -34,9 +33,8 @@ jobs: port: ${{ secrets.SSH_PORT }} script: | cd pw-backend - docker-compose down + docker-compose down -v docker image prune -a --force - git checkout master - git pull origin master - docker-compose build - docker-compose up -d + git checkout rpgf3 + git pull origin rpgf3 + docker-compose up -d --build diff --git a/.github/workflows/staging-deploy.yml b/.github/workflows/staging-deploy.yml new file mode 100644 index 0000000..7abe284 --- /dev/null +++ b/.github/workflows/staging-deploy.yml @@ -0,0 +1,25 @@ +name: staging-deploy-pipeline + +on: + push: + branches: + - staging + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: SSH and Redeploy Staging + uses: appleboy/ssh-action@v1.0.0 + with: + host: ${{ secrets.STAGING_HOST }} + username: ${{ secrets.STAGING_USERNAME }} + key: ${{ secrets.STAGING_PRIVATE_KEY }} + port: ${{ secrets.SSH_PORT }} + script: | + cd rpgf4-pw-backend + docker-compose down -v + docker image prune -a --force + git checkout master + git pull origin master + docker-compose up -d --build diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 86bac5c..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: test-pipeline - -on: - workflow_dispatch: - -jobs: - test: - runs-on: ubuntu-latest - - # Define the PostgreSQL service - services: - postgres: - image: postgres:15 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: my_db - ports: - - 5432:5432 - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - name: Wait for PostgreSQL db - uses: MaximeGoyette/wait-for-it-action@master - with: - host: postgres - port: 5432 - - name: Set up Node.js 18 - uses: actions/setup-node@v3 - with: - node-version: 18 - - name: Install Dependencies - run: | - npm install -g @nestjs/cli - npm install - - name: Build - run: npm run build - - name: Migrations - run: npx prisma migrate dev - env: - DATABASE_URL: postgresql://postgres:postgres@postgres:5432/my_db - NODE_ENV: staging - PORT: 7070 diff --git a/docker-compose.yml b/docker-compose.yml index 419a73c..479bff5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,35 +1,17 @@ -version: '3.9' +version: '3' services: pw-backend: - build: + build: context: . - container_name: pw-backend + container_name: rpgf4-pw-backend restart: always + ports: + - 7071:7070 networks: - pw-backend volumes: - ./data:/usr/src/app/data - caddy: - image: caddy:2-alpine - container_name: caddy - restart: always - networks: - - pw-backend - ports: - - 80:80 - - 443:443 - env_file: - - .env - environment: - PW_BACKEND_URL: ${PW_BACKEND_URL:-} - volumes: - - caddy_data:/data - - caddy_config:/config - - ./Caddyfile:/etc/caddy/Caddyfile networks: pw-backend: -volumes: - caddy_data: - caddy_config: