From 0f631f2f175d970f66e8d02f861e1491815c84ed Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar Date: Tue, 7 Jan 2025 22:11:56 +0530 Subject: [PATCH 1/3] feat: metaployficate --- Dockerfile | 6 +++--- docker-compose.yml | 25 +++++++++++++++++++++++++ metaploy/postinstall.sh | 14 ++++++++++++++ metaploy/travel.metaploy.conf | 11 +++++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 metaploy/postinstall.sh create mode 100644 metaploy/travel.metaploy.conf diff --git a/Dockerfile b/Dockerfile index aa44b64..db68f63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,8 +31,8 @@ COPY --from=base /app/.next ./.next COPY --from=base /app/public ./public COPY --from=base /app/node_modules ./node_modules -# Step 11: Expose the port Next.js runs on -EXPOSE 3000 +# Step 11: Copy metaploy stuff +COPY metaploy/ ./ # Step 12: Set the command to start the application -CMD ["npm", "start"] +CMD ["./postinstall.sh", "npm start"] diff --git a/docker-compose.yml b/docker-compose.yml index 5f536a6..b1c4a51 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,3 +8,28 @@ services: - "3000:3000" env_file: - .env + +services: + travel-buddy: + image: metakgporg/travel-buddy + container_name: travel-buddy-app + build: . + restart: always + env_file: + - .env + networks: + metaploy-network: + aliases: + - travel-buddy + volumes: + - nginx-config-volume:/etc/nginx/sites-enabled + +networks: + metaploy-network: + external: true + name: metaploy-network + +volumes: + nginx-config-volume: + external: true + name: metaploy-nginx-config-volume diff --git a/metaploy/postinstall.sh b/metaploy/postinstall.sh new file mode 100644 index 0000000..5f2bb0f --- /dev/null +++ b/metaploy/postinstall.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +cleanup() { + echo "Container stopped. Removing nginx configuration." + rm /etc/nginx/sites-enabled/travel.metaploy.conf +} + +trap 'cleanup' SIGQUIT SIGTERM SIGHUP + +"${@}" & + +cp ./iqps.metaploy.conf /etc/nginx/sites-enabled + +wait $! diff --git a/metaploy/travel.metaploy.conf b/metaploy/travel.metaploy.conf new file mode 100644 index 0000000..87e390c --- /dev/null +++ b/metaploy/travel.metaploy.conf @@ -0,0 +1,11 @@ +upstream travel_buddy { + server travel-buddy:3000; +} + +server { + server_name travel.metakgp.org; + + location / { + proxy_pass http://travel_buddy; + } +} \ No newline at end of file From c6ec5b24921797f122dde5a02e8c70a3647cfd72 Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar Date: Tue, 7 Jan 2025 22:12:06 +0530 Subject: [PATCH 2/3] feat: gh deploy workflow --- .github/workflows/deploy.yaml | 114 ++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..ddca1ea --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,114 @@ +name: Continuous Deployment Pipeline + +on: + push: + branches: + - "main" + +jobs: + dockerhub: + name: Publish Docker Image(s) to Dockerhub + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Cache Docker layers for Travel Buddy + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache-travel-buddy + key: ${{ runner.os }}-buildx-travel-buddy-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-travel-buddy- + + - name: Build & Push Travel Buddy + uses: docker/build-push-action@v5 + with: + context: ./ + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/travel-buddy-app:latest + cache-from: type=local,src=/tmp/.buildx-cache-travel-buddy + cache-to: type=local,dest=/tmp/.buildx-cache-travel-buddy-new,mode=max + + - name: Move Travel Buddy cache + run: | + rm -rf /tmp/.buildx-cache-travel-buddy + mv /tmp/.buildx-cache-travel-buddy-new /tmp/.buildx-cache-travel-buddy + + push: + name: Push Code Stage + needs: dockerhub + runs-on: ubuntu-latest + + steps: + - name: Sync local repo with remote repo + uses: appleboy/ssh-action@master + env: + PROJECT_DIR: ${{ secrets.PROJECT_DIR }} + with: + host: ${{ secrets.SSH_HOSTNAME }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }} + envs: PROJECT_DIR + script_stop: true + script: | + cd "${PROJECT_DIR}/" + sudo git fetch origin + sudo git reset --hard origin/main + + pull: + name: Pull Image Stage + needs: push + runs-on: ubuntu-latest + + steps: + - name: Pull the latest images(s) + uses: appleboy/ssh-action@master + env: + PROJECT_DIR: ${{ secrets.PROJECT_DIR }} + with: + host: ${{ secrets.SSH_HOSTNAME }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }} + envs: PROJECT_DIR + script_stop: true + script: | + cd "${PROJECT_DIR}/" + sudo docker compose pull + + deploy: + name: Deploy Stage + needs: pull + runs-on: ubuntu-latest + + steps: + - name: Deploy the latest build(s) + uses: appleboy/ssh-action@master + env: + PROJECT_DIR: ${{ secrets.PROJECT_DIR }} + with: + host: ${{ secrets.SSH_HOSTNAME }} + username: ${{ secrets.SSH_USERNAME }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }} + envs: PROJECT_DIR + script_stop: true + script: | + cd "${PROJECT_DIR}/" + sudo docker compose down + sudo docker compose up -d From 0a7fe9c80dc44b076834c52818c6660ab8370c2f Mon Sep 17 00:00:00 2001 From: Harsh Khandeparkar Date: Wed, 22 Jan 2025 13:42:47 +0530 Subject: [PATCH 3/3] whoopsie Co-authored-by: Arpit Bhardwaj --- metaploy/postinstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metaploy/postinstall.sh b/metaploy/postinstall.sh index 5f2bb0f..a206b42 100644 --- a/metaploy/postinstall.sh +++ b/metaploy/postinstall.sh @@ -9,6 +9,6 @@ trap 'cleanup' SIGQUIT SIGTERM SIGHUP "${@}" & -cp ./iqps.metaploy.conf /etc/nginx/sites-enabled +cp ./travel.metaploy.conf /etc/nginx/sites-enabled wait $!