Skip to content

Commit

Permalink
fix(cd): separate ports and docker-compose file for test deployment s…
Browse files Browse the repository at this point in the history
…ervice and developer service

Refactor the project to use distinct ports and Docker-compose files for the test deployment service
and the developer service. Introduce separate naming conventions and utilize new environment
variables for improved clarity and maintainability.
  • Loading branch information
quannhg committed Nov 18, 2023
1 parent c0d9f07 commit 1b18f84
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/remove-test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ permissions:

name: Remove test deploy

env:
- REGISTRY: ${{vars.REGISTRY_NAME}}

jobs:
remove:
name: Remove test deploying
Expand All @@ -18,7 +21,7 @@ jobs:
env:
TEST_DEPLOY_IMAGE_NAME: ticklabvn/ssps-be-test-deploy

if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.base.ref == 'staging'
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.base.ref == 'test/staging'

steps:
- name: remove
Expand Down
33 changes: 23 additions & 10 deletions .github/workflows/test-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
on:
pull_request:
types:
- opened
- opened
- synchronize

permissions:
contents: write
Expand All @@ -19,6 +20,7 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
if: github.event.pull_request.base.ref == 'test/staging'
steps:
- uses: actions/checkout@v3
name: Checkout repository
Expand Down Expand Up @@ -50,8 +52,8 @@ jobs:
runs-on: ubuntu-latest
needs: [build]
env:
POSTGRES_URL: postgresql://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@postgres:${{secrets.POSTGRES_PORT_TEST_DEPLOY}}/${{ secrets.POSTGRES_DB }}?schema=public
if: github.event_name == 'pull_request' && github.event.action == 'opened' && github.event.pull_request.base.ref == 'staging'
POSTGRES_URL: postgresql://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@postgres:${{secrets.POSTGRES_PORT}}/${{ secrets.POSTGRES_DB }}?schema=public
if: github.event.pull_request.base.ref == 'test/staging'
steps:
- name: Deploy
uses: appleboy/ssh-action@master
Expand All @@ -69,36 +71,47 @@ jobs:
mkdir -p $HOME/${{env.IMAGE_NAME}} && cd $HOME/${{env.IMAGE_NAME}}
rm -f .env
echo FASTIFY_PORT=${{ secrets.FASTIFY_PORT_TEST_DEPLOY }} >> .env
echo FASTIFY_PORT=${{ secrets.FASTIFY_PORT }} >> .env
echo FASTIFY_TEST_PORT=${{ secrets.FASTIFY_PORT_TEST_DEPLOY }} >> .env
echo >> .env
echo POSTGRES_USER=${{ secrets.POSTGRES_USER }} >> .env
echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} >> .env
echo POSTGRES_DB=${{ secrets.POSTGRES_DB }} >> .env
echo POSTGRES_PORT=${{ secrets.POSTGRES_PORT_TEST_DEPLOY }} >> .env
echo POSTGRES_PORT=${{ secrets.POSTGRES_PORT }} >> .env
echo POSTGRES_TEST_PORT=${{ secrets.POSTGRES_PORT_TEST_DEPLOY }} >> .env
echo POSTGRES_URL=${{ env.POSTGRES_URL }} >> .env
echo >> .env
echo CORS_WHITE_LIST=${{ secrets.CORS_WHITE_LIST }} >> .env
echo COOKIE_SECRET=${{ secrets.COOKIE_SECRET }} >> .env
echo JWT_SECRET=${{ secrets.JWT_SECRET }} >> .env
echo >> .env
echo MINIO_URL=${{ secrets.MINIO_URL }} >> .env
echo MINIO_SERVER_ENDPOINT=${{ secrets.MINIO_SERVER_ENDPOINT }} >> .env
echo MINIO_PORT=${{ secrets.MINIO_PORT }} >> .env
echo MINIO_ACCESS_KEY=${{ secrets.MINIO_ACCESS_KEY }} >> .env
echo MINIO_SECRET_KEY=${{ secrets.MINIO_SECRET_KEY }} >> .env
echo MINIO_BUCKET_NAME=${{ secrets.MINIO_BUCKET_NAME }} >> .env
echo >> .env
echo CHECKOUT_ENVIRONMENT=${{ vars.CHECKOUT_ENVIRONMENT }} >> .env
echo PAYPAL_LIVE_ENDPOINT=${{ vars.PAYPAL_LIVE_ENDPOINT }} >> .env
echo PAYPAL_SANDBOX_ENDPOINT=${{ vars.PAYPAL_SANDBOX_ENDPOINT }} >> .env
echo PAYPAL_CLIENT_ID=${{ secrets.PAYPAL_CLIENT_ID }} >> .env
echo PAYPAL_CLIENT_SECRET=${{ secrets.PAYPAL_CLIENT_SECRET }} >> .env
echo >> .env
echo GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} >> .env
echo GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} >> .env
echo GOOGLE_REDIRECT_URL=${{ secrets.GOOGLE_REDIRECT_URL }} >> .env
echo UI_HOME_URL=${{ secrets.UI_HOME_URL }} >> .env
echo >> .env
# curl -s ${{secrets.DOCKER_COMPOSE_RAW_FILE_URL}} -O -f
# docker compose stop ${{vars.DOCKER_COMPOSE_DEPLOY_SERVICE_NAME}}
# docker compose down --volumes --remove-orphans
# docker compose rm -f ${{vars.DOCKER_COMPOSE_DEPLOY_SERVICE_NAME}}
# docker compose up -d ${{vars.DOCKER_COMPOSE_DEPLOY_SERVICE_NAME}}
curl -s https://${{secrets.READ_FILE_ACCESS_TOKEN}}@raw.githubusercontent.com/${{github.repository}}/${{github.head_ref}}/docker-compose.test-deploy.yml -O -f
docker compose down --volumes --remove-orphans
docker compose -f docker-compose.test-deploy.yml up -d ${{vars.DOCKER_COMPOSE_DEPLOY_SERVICE_NAME}}
docker exec -it $(docker ps --filter "ancestor=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" -q) /bin/sh -c "npx prisma db seed"
Expand Down
43 changes: 43 additions & 0 deletions docker-compose.test-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: "3.5"
services:
postgres:
image: postgres:15
container_name: ssps-db-test-deploy
env_file:
- .env
ports:
- "${POSTGRES_TEST_PORT:-6432}:5432"
volumes:
- postgres_db:/var/lib/postgresql/data
restart: always
networks:
- ssps

#docker build -t ssps-be:test-deploy .
fastify:
image: ghcr.io/ticklabvn/ssps-be-test-deploy:latest
container_name: ssps-be-test-deploy
env_file:
- .env
ports:
- "${FASTIFY_TEST_PORT:-9080}:8080"
volumes:
- .env:/app/.env
depends_on:
- postgres
restart: always
networks:
- ssps

volumes:
postgres_db:

networks:
ssps:
name: ssps-test-deploy
external: true

# run the following command after docker compose up to create seed data:
# docker-compose exec fastify npx prisma db seed
# if the ssps network haven't created yet, run the following command:
# docker network create --driver bridge ssps-test-deploy

0 comments on commit 1b18f84

Please sign in to comment.