Skip to content

Commit

Permalink
Add terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
Vylpes committed Feb 6, 2024
1 parent 07237b8 commit d89d7bb
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 140 deletions.
17 changes: 9 additions & 8 deletions .dev.env → .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
# any secret values.

BOT_TOKEN=
BOT_VER=3.2 DEV
BOT_VER=3.2
BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816
BOT_CLIENTID=682942374040961060

ABOUT_FUNDING=https://ko-fi.com/vylpes
ABOUT_REPO=https://gitea.vylpes.xyz/RabbitLabs/vylbot-app

DB_HOST=127.0.0.1
DB_PORT=3101
DB_NAME=vylbot
DB_AUTH_USER=dev
DB_AUTH_PASS=dev
DB_SYNC=true
DB_LOGGING=true
DB_HOST=
DB_PORT=
DB_NAME=
DB_AUTH_USER=
DB_AUTH_PASS=
DB_SYNC=
DB_LOGGING=
DB_DATA_LOCATION=~/.docker
71 changes: 71 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Deploy To Production

on:
push:
branches:
- main

jobs:
build:
environment: prod

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 18.x
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn test

- name: RSync to Stage Server
uses: D3rHase/[email protected]
with:
HOST: ${{ secrets.SSH_HOST }}
PORT: ${{ secrets.SSH_PORT }}
USER: ${{ secrets.SSH_USER }}
PRIVATE_SSH_KEY: ${{ secrets.SSH_KEY }}
REPOSITORY_PATH: ${{ secrets.SSH_REPO_PATH }}
SERVER_PATH: ${{ secrets.SSH_SERVER_PATH }}

deploy:
environment: prod
needs: build
runs-on: ubuntu-latest
steps:
- uses: appleboy/[email protected]
env:
DB_NAME: ${{ secrets.DB_NAME }}
DB_AUTH_USER: ${{ secrets.DB_AUTH_USER }}
DB_AUTH_PASS: ${{ secrets.DB_AUTH_PASS }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_PORT: ${{ secrets.DB_PORT }}
DB_ROOT_HOST: ${{ secrets.DB_ROOT_HOST }}
DB_SYNC: ${{ secrets.DB_SYNC }}
DB_LOGGING: ${{ secrets.DB_LOGGING }}
DB_DATA_LOCATION: ${{ secrets.DB_DATA_LOCATION }}
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
BOT_VER: ${{ vars.BOT_VER }}
BOT_AUTHOR: ${{ vars.BOT_AUTHOR }}
BOT_OWNERID: ${{ vars.BOT_OWNERID }}
BOT_CLIENTID: ${{ vars.BOT_CLIENTID }}
ABOUT_FUNDING: ${{ vars.ABOUT_FUNDING }}
ABOUT_REPO: ${{ vars.ABOUT_FUNDING }}
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO
script: |
cd ~/app \
&& docker compose down \
&& (pm2 stop vylbot || true) \
&& (pm2 delete vylbot || true) \
&& docker compose up -d \
&& sleep 10 \
&& yarn run db:up \
&& pm2 start --name vylbot dist/vylbot.js
71 changes: 71 additions & 0 deletions .github/workflows/stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Deploy To Stage

on:
push:
branches:
- develop

jobs:
build:
environment: stage

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 18.x
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn test

- name: RSync to Stage Server
uses: D3rHase/[email protected]
with:
HOST: ${{ secrets.SSH_HOST }}
PORT: ${{ secrets.SSH_PORT }}
USER: ${{ secrets.SSH_USER }}
PRIVATE_SSH_KEY: ${{ secrets.SSH_KEY }}
REPOSITORY_PATH: ${{ secrets.SSH_REPO_PATH }}
SERVER_PATH: ${{ secrets.SSH_SERVER_PATH }}

deploy:
environment: stage
needs: build
runs-on: ubuntu-latest
steps:
- uses: appleboy/[email protected]
env:
DB_NAME: ${{ secrets.DB_NAME }}
DB_AUTH_USER: ${{ secrets.DB_AUTH_USER }}
DB_AUTH_PASS: ${{ secrets.DB_AUTH_PASS }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_PORT: ${{ secrets.DB_PORT }}
DB_ROOT_HOST: ${{ secrets.DB_ROOT_HOST }}
DB_SYNC: ${{ secrets.DB_SYNC }}
DB_LOGGING: ${{ secrets.DB_LOGGING }}
DB_DATA_LOCATION: ${{ secrets.DB_DATA_LOCATION }}
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
BOT_VER: ${{ vars.BOT_VER }}
BOT_AUTHOR: ${{ vars.BOT_AUTHOR }}
BOT_OWNERID: ${{ vars.BOT_OWNERID }}
BOT_CLIENTID: ${{ vars.BOT_CLIENTID }}
ABOUT_FUNDING: ${{ vars.ABOUT_FUNDING }}
ABOUT_REPO: ${{ vars.ABOUT_FUNDING }}
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO
script: |
cd ~/app \
&& docker compose down \
&& (pm2 stop vylbot || true) \
&& (pm2 delete vylbot || true) \
&& docker compose up -d \
&& sleep 10 \
&& yarn run db:up \
&& pm2 start --name vylbot dist/vylbot.js
26 changes: 26 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Testing

on:
push:
branches:
- feature/*
- hotfix/*

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn install
- run: yarn build
- run: yarn test
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,7 @@ dist

config.json
.DS_Store
ormconfig.json
ormconfig.json
.terraform
*.tfvars
*.tfstate
24 changes: 0 additions & 24 deletions .prod.env

This file was deleted.

24 changes: 0 additions & 24 deletions .stage.env

This file was deleted.

31 changes: 0 additions & 31 deletions docker-compose.prod.yml

This file was deleted.

31 changes: 0 additions & 31 deletions docker-compose.stage.yml

This file was deleted.

28 changes: 7 additions & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
version: "3.9"

volumes:
dev_database_data:

services:
# discord:
# build: .

database:
image: mysql/mysql-server
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
- MYSQL_DATABASE=vylbot
- MYSQL_USER=dev
- MYSQL_PASSWORD=dev
- MYSQL_ROOT_PASSWORD=root
- MYSQL_ROOT_HOST=0.0.0.0
- MYSQL_DATABASE=$DB_NAME
- MYSQL_USER=$DB_AUTH_USER
- MYSQL_PASSWORD=$DB_AUTH_PASS
- MYSQL_ROOT_PASSWORD=$DB_AUTH_PASS
- MYSQL_ROOT_HOST=$DB_ROOT_HOST
ports:
- "3101:3306"
- "3306:3306"
volumes:
- dev_database_data:/var/lib/mysql

phpmyadmin:
image: phpmyadmin
restart: always
ports:
- "3102:80"
environment:
- PMA_ARBITRARY=1
- $DB_DATA_LOCATION:/var/lib/mysql
Loading

0 comments on commit d89d7bb

Please sign in to comment.