From 48e27620c4073b88e3a83bbb440cd3a7ebbd084e Mon Sep 17 00:00:00 2001 From: Veivel <25278964+Veivel@users.noreply.github.com> Date: Tue, 18 Jun 2024 14:12:32 +0700 Subject: [PATCH] feature: modify deployment files, add docker compose to gh action --- .github/workflows/deploy-staging.yaml | 14 ++++++- Dockerfile | 5 ++- deploy-stg/docker-compose.yml | 16 +++---- deploy-stg/infisical.py | 4 +- ...equirements.txt => setup-requirements.txt} | 0 docker-compose-deploy.yaml | 42 ------------------- docker-compose-dev-full.yaml | 2 +- 7 files changed, 28 insertions(+), 55 deletions(-) rename deploy-stg/{requirements.txt => setup-requirements.txt} (100%) delete mode 100644 docker-compose-deploy.yaml diff --git a/.github/workflows/deploy-staging.yaml b/.github/workflows/deploy-staging.yaml index e64cec5..0cd45ed 100644 --- a/.github/workflows/deploy-staging.yaml +++ b/.github/workflows/deploy-staging.yaml @@ -54,7 +54,7 @@ jobs: id: install-py-dependencies run: | python -m pip install --upgrade pip - pip install -r deploy-stg/requirements.txt + pip install -r deploy-stg/setup-requirements.txt - name: Setup Infisical id: setup-infisical @@ -99,3 +99,15 @@ jobs: remote_user: ${{ secrets.SSH_USER }} remote_key: ${{ secrets.SSH_KEY_OVERRIDE }} + - name: SSH and Docker Compose Up + id: ssh-docker-compose + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SSH_IP_ADDRESS }} + username: ${{ secrets.SSH_USER }} + key: ${{ secrets.SSH_KEY_OVERRIDE }} + port: ${{ secrets.SSH_PORT }} + script: | + cd susunjadwal/susunjadwal-backend-stg + docker compose up + diff --git a/Dockerfile b/Dockerfile index 82f6eea..42dda22 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,7 @@ ENV APP_ENV="container" COPY . . +COPY launch.sh /opt/app/launch.sh COPY sso/additional-info.json /opt/app/sso/additional-info.json COPY sso/faculty-base-additional-info.json /opt/app/sso/faculty-base-additional-info.json COPY sso/faculty_exchange_route.json /opt/app/sso/faculty_exchange_route.json @@ -14,6 +15,6 @@ RUN apk add -u --no-cache tzdata gcc musl-dev libxml2 libxslt-dev && \ pip install wheel && \ pip install -r requirements.txt -ENV PORT=8000 +ENV PORT=8006 -ENTRYPOINT ["/bin/sh","launch.sh"] \ No newline at end of file +ENTRYPOINT ["/opt/app","launch.sh"] \ No newline at end of file diff --git a/deploy-stg/docker-compose.yml b/deploy-stg/docker-compose.yml index 1625f4b..a2b2bdf 100644 --- a/deploy-stg/docker-compose.yml +++ b/deploy-stg/docker-compose.yml @@ -1,7 +1,7 @@ version: "3.9" services: - susunjadwal-backend-rmq-stg: + rmq-stg: image: rabbitmq:management-alpine restart: unless-stopped ports: @@ -9,7 +9,7 @@ services: networks: - public-web - susunjadwal-backend-mongo-stg: + mongo-stg: image: mongo:7 restart: unless-stopped environment: @@ -23,19 +23,21 @@ services: networks: - public-web - susunjadwal-backend-server-stg: + server-stg: image: ristekoss/susunjadwal-backend:staging labels: caddy: api-stg.susunjadwal.ristek.cs.ui.ac.id - caddy.reverse_proxy: "{{upstreams 8000}}" + caddy.reverse_proxy: "{{upstreams 8006}}" restart: unless-stopped depends_on: - rmq-stg - mongo-stg - volumes: - - ./.env:/app/.env:ro + # volumes: + # - ./.env:/app/.env:ro + env_file: + - .env ports: - - 8005:8005 + - 8006:8006 networks: - public-web diff --git a/deploy-stg/infisical.py b/deploy-stg/infisical.py index 90f15c4..4dedc7b 100644 --- a/deploy-stg/infisical.py +++ b/deploy-stg/infisical.py @@ -64,7 +64,7 @@ stdout=open(Path("deploy-stg") / ".env", "w"), stderr=sys.stderr, ) - logger.info(f"Initial .env file size: {os.stat(Path('deploy-stg') / '.env').st_size}") + logger.info(f"Initial .env file size: {os.stat(Path('deploy-stg') / '.env').st_size} bytes") # Strip quotes if not quoted (Infisical exports for .env by default is quoted) if not quoted: @@ -86,4 +86,4 @@ for var in quoted_vars: env_file.write(var + "\n") - logger.info(f"Final .env file size: {os.stat(Path('deploy-stg') / '.env').st_size}") \ No newline at end of file + logger.info(f"Final .env file size: {os.stat(Path('deploy-stg') / '.env').st_size} bytes") \ No newline at end of file diff --git a/deploy-stg/requirements.txt b/deploy-stg/setup-requirements.txt similarity index 100% rename from deploy-stg/requirements.txt rename to deploy-stg/setup-requirements.txt diff --git a/docker-compose-deploy.yaml b/docker-compose-deploy.yaml deleted file mode 100644 index d15bb74..0000000 --- a/docker-compose-deploy.yaml +++ /dev/null @@ -1,42 +0,0 @@ -version: "3.3" - -services: - rmq: - restart: always - image: rabbitmq:management-alpine - ports: - - "15671-15672:15671-15672" - - mongo: - restart: always - build: - dockerfile: MongoDB-Dockerfile - context: . - environment: - MONGO_INITDB_ROOT_USERNAME: root-user - MONGO_INITDB_ROOT_PASSWORD: root-user - MONGO_INITDB_USERNAME: user - MONGO_INITDB_PASSWORD: user - MONGO_INITDB_DATABASE: backend - volumes: - - sunjad_db:/data/db - - server: - build: - dockerfile: Dockerfile - context: . - restart: always - depends_on: - - rmq - - mongo - env_file: - - .env - ports: - - "8000:8000" - volumes: - - ./sso/additional-info.json:/opt/app/sso/additional-info.json - - ./sso/faculty-base-additional-info.json:/opt/app/sso/faculty-base-additional-info.json - - ./sso/faculty_exchange_route.json:/opt/app/sso/faculty_exchange_route.json - -volumes: - sunjad_db: \ No newline at end of file diff --git a/docker-compose-dev-full.yaml b/docker-compose-dev-full.yaml index a229692..7e42bdf 100644 --- a/docker-compose-dev-full.yaml +++ b/docker-compose-dev-full.yaml @@ -30,7 +30,7 @@ services: env_file: - .env ports: - - 8005:8005 + - 8005:8000 volumes: sunjad_db: \ No newline at end of file