Skip to content

Commit

Permalink
Baseline for Master (#12)
Browse files Browse the repository at this point in the history
* Working on Github Actions.

* Working on Deployment.

* Fix: Github Actions.

* Fixed username.

* Working on deployment.

* Update clone-and-setup.yml

* Update clone-and-setup.yml

* Update clone-and-setup.yml

* sanity commit.

* snaity commit.

* s.

* sc.

* logging.

* Update app-deployment.yml

* Update app-deployment.yml

* Update db-operations.yml

* Update db-operations.yml

* Update db-operations.yml

* Update db-operations.yml

* Update db-operations.yml

* Removing unused classes.

* Update db-operations.yml

* Update db-operations.yml

* Update app-deployment.yml

* Update app-deployment.yml

* Working on deployment.

* Update db-operations.yml

* Update db-operations.yml

* Update package.json

* Working on Deployment migration runner.

* Fixing docker network.

* sc

* Working on UI fixes.

* Working on QR Download and schema changes.

* Working on decoupling action from formData.

* Minor changes.

* Logging the migrations.

* Debugging.

* changing env name.

* Update app-deployment.yml
  • Loading branch information
abhik-wil authored Jan 7, 2025
1 parent 40b832b commit ad62ce3
Show file tree
Hide file tree
Showing 31 changed files with 902 additions and 167 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/app-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: App Deployment
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
deploy-app:
runs-on: ubuntu-latest
steps:
- name: Deploy Generator App
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PEM }}
port: 22
script: |
echo "STARTING Deployment"
[ -d "deeplink-resolver-server" ] && sudo rm -rf "deeplink-resolver-server"
sudo git clone https://github.com/abhik-wil/deeplink-resolver-server.git
cd deeplink-resolver-server/deeplink-generator
echo "STARTING Deployment"
sudo touch .env
# Create backend .env file
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" | sudo tee .env
echo "POSTGRES_USER=${{ secrets.POSTGRES_USER }}" | sudo tee -a .env
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" | sudo tee -a .env
echo "POSTGRES_DB=${{ secrets.POSTGRES_DB }}" | sudo tee -a .env
echo "ACCESS_TOKEN_REPO=${{ secrets.ACCESS_TOKEN_REPO }}" | sudo tee -a .env
echo "OWNER_NAME_REPO=${{ secrets.OWNER_NAME_REPO }}" | sudo tee -a .env
echo "STORAGE_REPO_NAME=${{ secrets.STORAGE_REPO_NAME }}" | sudo tee -a .env
echo "STARTING build"
sudo cp docker-compose.dev.yml docker-compose.yml
sudo docker compose up ondc_deep_link_app -d --build
sudo docker system prune -f
echo "BUILD Complete; Restarting Nginx"
sudo systemctl restart nginx
echo "Deployment COMPLETE"
29 changes: 29 additions & 0 deletions .github/workflows/db-operations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Database Operations
on:
workflow_dispatch:

jobs:
db-reset-and-migrate:
runs-on: ubuntu-latest
steps:
- name: Execute Generator DB Operations
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PEM }}
port: 22
script: |
cd deeplink-resolver-server/deeplink-generator
echo "DB Teardown and Restart"
sudo docker compose down ondc_deep_link_db
sudo docker compose up -d ondc_deep_link_db
sleep 10
sudo docker build -t migrations-runner -f Dockerfile.migration .
sudo docker run --rm \
--network deeplink-generator_default \
migrations-runner
2 changes: 2 additions & 0 deletions deeplink-generator/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
docker-compose.yml

10 changes: 10 additions & 0 deletions deeplink-generator/Dockerfile.migration
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:22-alpine

WORKDIR /app

COPY package*.json ./
COPY . .

RUN npm install

CMD ["sh", "-c", "npx prisma generate && npx prisma migrate deploy && node seeding/seed.js"]
25 changes: 25 additions & 0 deletions deeplink-generator/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
ondc_deep_link_app:
build: .
ports:
- "8080:3000"
env_file:
- ./.env
depends_on:
- ondc_deep_link_db

ondc_deep_link_db:
image: postgres
restart: always
# set shared memory limit when using docker-compose
shm_size: 128mb
# or set shared memory limit when deploy via swarm stack
#volumes:
# - type: tmpfs
# target: /dev/shm
# tmpfs:
# size: 134217728 # 128*2^20 bytes = 128Mb
ports:
- "5432:5432"
env_file:
- ./.env
File renamed without changes.
9 changes: 7 additions & 2 deletions deeplink-generator/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
/* config options here */
output: "standalone"
/* config options here */
output: "standalone",
images: {
remotePatterns: [
{ protocol: "https", hostname: "raw.githubusercontent.com" },
],
},
};

export default nextConfig;
25 changes: 9 additions & 16 deletions deeplink-generator/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,24 @@

http {
upstream nextjs_upstream {
server host.docker.internal:8080;
server localhost:8080;
}

server {
listen 80;
listen [::]:80;
server_name _;
server_name deeplink.resolver.ondc.org;

location / {
proxy_pass http://nextjs_upstream;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl;
listen [::]:443 ssl;
server_name _;

ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;

ssl_certificate /etc/letsencrypt/live/deeplink.resolver.ondc.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/deeplink.resolver.ondc.org/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;

Expand All @@ -49,3 +38,7 @@ http {
}
}
}

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
Loading

0 comments on commit ad62ce3

Please sign in to comment.