Skip to content

Commit

Permalink
Merge pull request #22 from Apillon/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
MoMannn authored Feb 19, 2024
2 parents 42d430b + 3bee47d commit 3902d4a
Show file tree
Hide file tree
Showing 56 changed files with 967 additions and 255 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy Website

on:
push:
branches:
- staging

defaults:
run:
working-directory: ./frontend

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
run: npm install

- name: Build application
run: npm run generate

- name: Deploy website
env:
APILLON_API_KEY: ${{ secrets.APILLON_API_KEY }}
APILLON_API_SECRET: ${{ secrets.APILLON_API_SECRET }}
WEBSITE_UUID: ${{ secrets.WEBSITE_UUID_STAGING }}
run: |
npm i -g @apillon/cli
apillon hosting deploy-website ./.output/public --uuid $WEBSITE_UUID --key $APILLON_API_KEY --secret $APILLON_API_SECRET
38 changes: 38 additions & 0 deletions .github/workflows/deploy_production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy production Website

on:
push:
branches:
- main

defaults:
run:
working-directory: ./frontend

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
run: npm install

- name: Build application
run: npm run generate

- name: Deploy website
env:
APILLON_API_KEY: ${{ secrets.APILLON_API_KEY }}
APILLON_API_SECRET: ${{ secrets.APILLON_API_SECRET }}
WEBSITE_UUID: ${{ secrets.WEBSITE_UUID }}
run: |
npm i -g @apillon/cli
apillon hosting deploy-website ./.output/public --uuid $WEBSITE_UUID --key $APILLON_API_KEY --secret $APILLON_API_SECRET
31 changes: 31 additions & 0 deletions backend/bin/create-database.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

if [ "$#" -ne 4 ]; then
echo "Usage: $0 <database_host> <database_name> <mysql_user> <mysql_password>"
exit 1
fi

DATABASE_HOST=$1
DATABASE_NAME=$2
MYSQL_USER=$3
MYSQL_PASSWORD=$4

echo "Connecting to host: $DATABASE_HOST"
ping -c 3 $DATABASE_HOST

export MYSQL_PWD=$MYSQL_PASSWORD

# Check if the database exists
DB_EXISTS=$(mysql -h $DATABASE_HOST -u $MYSQL_USER -e "SHOW DATABASES LIKE '$DATABASE_NAME';" | grep "$DATABASE_NAME")

if [ "$DB_EXISTS" == "$DATABASE_NAME" ]; then
echo "Database $DATABASE_NAME already exists. Exiting."
exit 0
fi

# Create the database
mysql -h $DATABASE_HOST -u $MYSQL_USER -e "CREATE DATABASE $DATABASE_NAME;"

unset MYSQL_PWD

echo "Database $DATABASE_NAME created successfully."
14 changes: 14 additions & 0 deletions backend/bin/docker-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
printenv

echo "Waiting 1m for DB image to start"
sleep 1m

echo "Crating database..."
./bin/create-database.sh "$MYSQL_HOST" "$MYSQL_DB" "$MYSQL_USER" "$MYSQL_PASSWORD"

# migrate DB
echo "Starting migration!"
npm run db-upgrade:ci

pm2 start pm2.config.js --attach
4 changes: 4 additions & 0 deletions backend/build-image-beta.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/i0e4n2k8
docker build -t ment-airdrop:beta.0 .
docker tag ment-airdrop:beta.0 public.ecr.aws/i0e4n2k8/ment-airdrop:beta.0
docker push public.ecr.aws/i0e4n2k8/ment-airdrop:beta.0
4 changes: 4 additions & 0 deletions backend/build-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/i0e4n2k8
docker build -t ment-airdrop:latest .
docker tag ment-airdrop:latest public.ecr.aws/i0e4n2k8/ment-airdrop:latest
docker push public.ecr.aws/i0e4n2k8/ment-airdrop:latest
47 changes: 47 additions & 0 deletions backend/docker-compose.beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: '3.8'

services:
airdrop_db:
image: mysql
container_name: airdrop_db
env_file:
- .env.sql.deploy
# environment:
# MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
# MYSQL_DATABASE: ${MYSQL_DATABASE}
ports:
- '3306:3306'
restart: always
volumes:
- mysql-data:/var/lib/mysql

airdrop_app:
image: public.ecr.aws/i0e4n2k8/ment-airdrop:beta.0
container_name: airdrop_app
depends_on:
- airdrop_db
env_file:
- .env.deploy
# environment:
# APP_SECRET: ${APP_SECRET}
# APP_URL: ${APP_URL}
# ADMIN_WALLET: ${ADMIN_WALLET}
# APILLON_KEY: ${APILLON_KEY}
# APILLON_SECRET: ${APILLON_SECRET}
# COLLECTION_UUID: ${COLLECTION_UUID}
# SMTP_HOST: ${SMTP_HOST}
# SMTP_PORT: ${SMTP_PORT}
# SMTP_USERNAME: ${SMTP_USERNAME}
# SMTP_PASSWORD: ${SMTP_PASSWORD}
# SMTP_EMAIL_FROM: ${SMTP_EMAIL_FROM}
# SMTP_NAME_FROM: ${SMTP_NAME_FROM}
# API_HOST: ${API_HOST}
# API_PORT: ${API_PORT}
# CAPTCHA_SECRET: ${CAPTCHA_SECRET}
# CLAIM_EXPIRES_IN: ${CLAIM_EXPIRES_IN}
ports:
- '8080:${API_PORT}'
restart: always

volumes:
mysql-data:
43 changes: 43 additions & 0 deletions backend/docker-compose.proxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
services:
proxy:
image: nginxproxy/nginx-proxy:latest
container_name: nginx-proxy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- /app/certs:/etc/nginx/certs:ro
# - /etc/nginx/vhost.d
# - /usr/share/nginx/html
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
environment:
- HTTPS_METHOD=noredirect
networks:
- web

proxy-ssl:
image: nginxproxy/acme-companion
container_name: acme-companion
restart: unless-stopped
volumes_from:
- proxy
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /app/certs:/etc/nginx/certs:rw
- acme:/etc/acme.sh
environment:
- [email protected]
networks:
- web

volumes:
vhost:
html:
acme:

networks:
web:
name: web
36 changes: 36 additions & 0 deletions backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.8'

services:
airdrop_db:
image: mysql
container_name: airdrop_db
env_file:
- .env.sql.deploy
ports:
- '3306:3306'
restart: always
volumes:
- mysql-data:/var/lib/mysql
networks:
- db

airdrop_app:
image: public.ecr.aws/i0e4n2k8/ment-airdrop:latest
container_name: airdrop_app
depends_on:
- airdrop_db
env_file:
- .env.deploy
restart: always
networks:
- web
- db

volumes:
mysql-data:

networks:
db:
web:
name: web
external: true
51 changes: 51 additions & 0 deletions backend/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM node:20-alpine

ENV APP_ENV=production
ARG APP_SECRET
#should be overriden
ENV APP_URL=http://localhost:3000
ENV API_PORT=3000

ENV MYSQL_HOST=airdrop_db
ENV MYSQL_PORT=3306
ENV MYSQL_DB=airdrop
ENV MYSQL_USER=root
ARG MYSQL_PASSWORD
ENV MYSQL_POOL=5

ARG ADMIN_WALLET
ARG APILLON_KEY
ARG APILLON_SECRET
ARG COLLECTION_UUID

ARG SMTP_HOST
ARG SMTP_PORT
ARG SMTP_USERNAME
ARG SMTP_PASSWORD
ARG SMTP_EMAIL_FROM
ARG SMTP_NAME_FROM

RUN echo $MYSQL_HOST

ENV appDir /app
RUN mkdir -p /app

WORKDIR ${appDir}

# Install MySQL client
RUN apk --no-cache add mysql-client

RUN npm install -g typescript pm2@latest

ADD ./package-lock.json ${appDir}
ADD ./package.json ${appDir}
ADD ./ ${appDir}/

RUN npm install
RUN npm run build
RUN mkdir -p ./dist/templates/mail/
RUN cp ./src/templates/mail/*.html ./dist/templates/mail/

EXPOSE 3000
RUN chmod +x ./bin/docker-start.sh ./bin/create-database.sh
CMD ["./bin/docker-start.sh"]
8 changes: 4 additions & 4 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"cron": "node -r ts-node/register --inspect ./src/scripts/start-cron",
"dev": "npm run development:run",
"tsc": "tsc",
"build": "tsc",
"db-upgrade": "node -r ts-node/register ./src/scripts/db/upgrade-db",
"db-upgrade:ci": "node -r ts-node/register ./src/scripts/db/upgrade-db --F",
"db-downgrade": "node -r ts-node/register ./src/scripts/db/downgrade-db",
"db-rebuild": "node -r ts-node/register ./src/scripts/db/rebuild-db",
"db-drop": "node -r ts-node/register ./src/scripts/db/drop-db"
Expand All @@ -30,7 +32,7 @@
"jsonwebtoken": "^9.0.2",
"moment": "^2.29.4",
"mysql2": "^3.6.5",
"nodemailer": "^6.9.7",
"nodemailer": "^6.9.9",
"reflect-metadata": "^0.1.13",
"sqlstring": "^2.3.3",
"ts-node": "^10.9.1"
Expand All @@ -50,4 +52,4 @@
},
"author": "Apillon",
"license": "ISC"
}
}
14 changes: 14 additions & 0 deletions backend/pm2.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
apps: [
{
name: 'http-server',
script: './dist/scripts/start-http.js',
restart_delay: 3000,
},
{
name: 'cron',
script: './dist/scripts/start-cron.js',
restart_delay: 3000,
},
],
};
Loading

0 comments on commit 3902d4a

Please sign in to comment.