diff --git a/.github/workflows/pr-deploy.yaml b/.github/Unused/pr-deploy.yaml similarity index 100% rename from .github/workflows/pr-deploy.yaml rename to .github/Unused/pr-deploy.yaml diff --git a/.github/workflows/dev-deployment.yaml b/.github/workflows/dev-deployment.yaml deleted file mode 100644 index 840a32fd6..000000000 --- a/.github/workflows/dev-deployment.yaml +++ /dev/null @@ -1,48 +0,0 @@ -name: Dev Deployment - -on: - workflow_dispatch: - push: - branches: - - dev - -jobs: - build-and-push: - if: github.event.repository.fork == false - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Build Docker image - run: docker build -t nestjs_dev:green . - - - name: Save and compress Docker image - run: | - docker save nestjs_dev:green | gzip > nestjs_dev.tar.gz - - - name: Copy image to server - uses: appleboy/scp-action@master - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - password: ${{ secrets.PASSWORD }} - source: "nestjs_dev.tar.gz" - target: "/tmp" - - deploy: - needs: build-and-push - runs-on: ubuntu-latest - environment: - name: "dev" - url: ${{ vars.URL }} - steps: - - name: Deploy on server - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - password: ${{ secrets.PASSWORD }} - script: | - cd ~/hng_boilerplate_nestjs - ./deploy.sh dev diff --git a/.github/workflows/main-deployment.yaml b/.github/workflows/main-deployment.yaml new file mode 100644 index 000000000..e3569d46e --- /dev/null +++ b/.github/workflows/main-deployment.yaml @@ -0,0 +1,22 @@ +name: Production Deployment + +on: + workflow_dispatch: + push: + branches: + - main + +jobs: + deploy-prod: + runs-on: bingo-server + steps: + - name: Deploy on server + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + script: | + cd main + chmod +x deployment.sh + ./deployment.sh main diff --git a/.github/workflows/production-deployment.yaml b/.github/workflows/production-deployment.yaml deleted file mode 100644 index 7ce95863d..000000000 --- a/.github/workflows/production-deployment.yaml +++ /dev/null @@ -1,47 +0,0 @@ -name: Production Deployment - -on: - workflow_dispatch: - push: - branches: - - main - -jobs: - build-and-push: - if: github.event.repository.fork == false - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Build Docker image - run: docker build -t nestjs_prod:green . - - - name: Save and compress Docker image - run: | - docker save nestjs_prod:green | gzip > nestjs_prod.tar.gz - - - name: Copy image to server - uses: appleboy/scp-action@master - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - password: ${{ secrets.PASSWORD }} - source: "nestjs_prod.tar.gz" - target: "/tmp" - - deploy: - needs: build-and-push - runs-on: ubuntu-latest - environment: - name: "production" - url: ${{ vars.URL }} - steps: - - name: Deploy on server - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - password: ${{ secrets.PASSWORD }} - script: | - ./deploy.sh prod diff --git a/.github/workflows/staging-deployment.yaml b/.github/workflows/staging-deployment.yaml index 7e7af63ed..cebd7ec25 100644 --- a/.github/workflows/staging-deployment.yaml +++ b/.github/workflows/staging-deployment.yaml @@ -7,35 +7,8 @@ on: - staging jobs: - build-and-push: - if: github.event.repository.fork == false - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Build Docker image - run: docker build -t nestjs_staging:green . - - - name: Save and compress Docker image - run: | - docker save nestjs_staging:green | gzip > nestjs_staging.tar.gz - - - name: Copy image to server - uses: appleboy/scp-action@master - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - password: ${{ secrets.PASSWORD }} - source: 'nestjs_staging.tar.gz' - target: '/tmp' - - deploy: - needs: build-and-push - runs-on: ubuntu-latest - environment: - name: 'staging' - url: ${{ vars.URL }} + deploy-staging: + runs-on: bingo-server steps: - name: Deploy on server uses: appleboy/ssh-action@master @@ -44,5 +17,6 @@ jobs: username: ${{ secrets.USERNAME }} password: ${{ secrets.PASSWORD }} script: | - cd ~/hng_boilerplate_nestjs - ./deploy.sh staging + cd staging + chmod +x deployment.sh + ./deployment.sh staging diff --git a/compose.override.yaml b/compose/compose.override.yaml similarity index 100% rename from compose.override.yaml rename to compose/compose.override.yaml diff --git a/compose.yaml b/compose/compose.yaml similarity index 87% rename from compose.yaml rename to compose/compose.yaml index 80344a477..335a2e94f 100644 --- a/compose.yaml +++ b/compose/compose.yaml @@ -12,7 +12,7 @@ services: redis: condition: service_healthy healthcheck: - test: "wget -qO- http://app:${PORT}" + test: 'wget -qO- http://app:${PORT}' interval: 10s timeout: 10s retries: 3 @@ -28,7 +28,7 @@ services: volumes: - postgres_data:/var/lib/postgresql/data healthcheck: - test: "pg_isready -U postgres" + test: 'pg_isready -U postgres' interval: 5s timeout: 5s retries: 3 @@ -41,7 +41,7 @@ services: volumes: - redis_data:/data healthcheck: - test: "redis-cli ping | grep PONG" + test: 'redis-cli ping | grep PONG' interval: 5s timeout: 5s retries: 3 @@ -55,7 +55,7 @@ services: app: condition: service_healthy healthcheck: - test: "wget -qO- http://nginx:80" + test: 'wget -qO- http://nginx:80' interval: 5s timeout: 5s retries: 3 diff --git a/deploy.sh b/compose/deploy.sh similarity index 100% rename from deploy.sh rename to compose/deploy.sh diff --git a/deployment.sh b/deployment.sh new file mode 100644 index 000000000..d23d9bd37 --- /dev/null +++ b/deployment.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +BRANCH=$1 + +# checkout +git checkout $BRANCH; + +git pull origin $BRANCH; + +# install dependencies +npm install --include=dev; + +# run build +npm run build; + + +git stash + +# run migration +npm run migration:run; + +# run start +pm2 restart $BRANCH-ecosystem-config.json || pm2 start $BRANCH-ecosystem-config.json; diff --git a/main-ecosystem-config.json b/main-ecosystem-config.json index 220d76794..d31030f0d 100644 --- a/main-ecosystem-config.json +++ b/main-ecosystem-config.json @@ -1,11 +1,11 @@ { "apps": [ { - "name": "team-alpha-prod", + "name": "nestjs-prod", "script": "npm run start:prod", "log_file": "~/.pm2/logs/team-alpha-prod-out.log", "combine_logs": true, "log_date_format": "YYYY-MM-DD HH:mm:ss Z" } ] -} \ No newline at end of file +} diff --git a/staging-ecosystem-config.json b/staging-ecosystem-config.json index d8fa81c86..48d1d822b 100644 --- a/staging-ecosystem-config.json +++ b/staging-ecosystem-config.json @@ -1,11 +1,11 @@ { "apps": [ { - "name": "team-alpha-staging", + "name": "nestjs2-staging", "script": "npm run start:prod", "log_file": "~/.pm2/logs/team-alpha-staging-out.log", "combine_logs": true, "log_date_format": "YYYY-MM-DD HH:mm:ss Z" } ] -} \ No newline at end of file +}