Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metaploy #28

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions metaploy/postinstall.sh
Original file line number Diff line number Diff line change
@@ -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 ./travel.metaploy.conf /etc/nginx/sites-enabled

wait $!
11 changes: 11 additions & 0 deletions metaploy/travel.metaploy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
upstream travel_buddy {
server travel-buddy:3000;
}

server {
server_name travel.metakgp.org;

location / {
proxy_pass http://travel_buddy;
}
}