Skip to content

Commit

Permalink
chore: setup automatic deploy dev
Browse files Browse the repository at this point in the history
  • Loading branch information
guesant committed Feb 7, 2024
1 parent 7613058 commit dc88178
Show file tree
Hide file tree
Showing 10 changed files with 8,996 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/cd-development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: deploy to the development environment

on:
push:
branches: [development]

permissions:
contents: read # for checkout

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.LUNA_CD_SSH_HOST }}
username: ${{ secrets.LUNA_CD_SSH_USERNAME }}
key: ${{ secrets.LUNA_CD_SSH_KEY }}
port: ${{ secrets.LUNA_CD_SSH_PORT }}
script_stop: true
script: |
mkdir -p /lunatic/repos;
cd /lunatic/repos;
if [ ! -d luna ]; then
git clone https://github.com/sisgha/luna -b development luna;
fi
chgrp -R 1000 luna;
chown -R 1000 luna;
git config --global --add safe.directory /lunatic/repos/luna;
cd luna;
cd luna-backend;
make dev-setup;
make dev-down;
(git branch -D temp-fix 2>/dev/null; exit 0);
git checkout -b temp-fix;
git branch -D development;
git fetch origin;
git checkout -b development --track origin/development;
git pull origin development;
make dev-start;
58 changes: 58 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# compiled output
/dist
/node_modules
/build

*.env

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
5 changes: 5 additions & 0 deletions luna-backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/.git
**/*.env
**/*.env*
**/node_modules
Dockerfile
2 changes: 2 additions & 0 deletions luna-backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/node_modules
/build

*.env

# Logs
logs
*.log
Expand Down
21 changes: 21 additions & 0 deletions luna-backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:18 as base
RUN apt update -y
RUN apt install -y git
WORKDIR /luna-container/luna-backend

FROM base as prod-deps
COPY package.json .npmrc package-lock.json ./
RUN npm install --omit=dev

FROM prod-deps as dev-deps
RUN npm install

FROM dev-deps as assets
COPY . .
RUN npm run build
RUN rm -rf node_modules

FROM prod-deps
COPY --from=assets /luna-container/luna-backend /luna-container/luna-backend
WORKDIR /luna-container/luna-backend
CMD npm run db:migrate && npm run seed:run && npm run start:prod
26 changes: 26 additions & 0 deletions luna-backend/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
dev-setup:

$(shell (cd devops/development; find . -type f -name "*.example" -exec sh -c 'cp -n {} $$(basename {} .example)' \;))

$(shell (bash -c "sudo docker network create sisgea-luna-net &>/dev/null"))

dev-up:
make dev-setup;
sudo docker compose --file devops/development/docker-compose.yml -p sisgea-luna-backend up -d --remove-orphans;

dev-shell:
make dev-up;
sudo docker compose --file devops/development/docker-compose.yml -p sisgea-luna-backend exec sisgea-luna-backend bash;

dev-down:
sudo docker compose --file devops/development/docker-compose.yml -p sisgea-luna-backend stop

dev-logs:
sudo docker compose --file devops/development/docker-compose.yml -p sisgea-luna-backend logs -f


dev-start:
make dev-down;
make dev-up;

sudo docker compose --file devops/development/docker-compose.yml -p sisgea-luna-backend exec --no-TTY -d sisgea-luna-backend bash -c "npm i && npm run start:dev" \&;
3 changes: 3 additions & 0 deletions luna-backend/devops/development/.db.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POSTGRESQL_DATABASE=main
# POSTGRESQL_USERNAME=postgres
POSTGRESQL_PASSWORD=7f22682363b549a389e03b7fe512488b
Empty file.
36 changes: 36 additions & 0 deletions luna-backend/devops/development/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
services:
sisgea-luna-backend:
image: node:20
user: node
command: sh -c "tail -f /dev/null"
container_name: sisgea-luna-backend
working_dir: /container/code
depends_on:
- sisgea-luna-backend-db
networks:
- sisgea-luna-net
ports:
- 3000:3000
volumes:
- ../../../../../libs:/sisgea/env-dev/libs
- ../../:/container/code
env_file:
- .env

sisgea-luna-backend-db:
image: bitnami/postgresql:15
container_name: sisgea-luna-backend-db
volumes:
- 'sisgea-luna-backend-db-data:/bitnami/postgresql'
- './volumes/db/scripts/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d'
networks:
- sisgea-luna-net
env_file:
- .db.env

networks:
sisgea-luna-net:
external: true

volumes:
sisgea-luna-backend-db-data:
Loading

0 comments on commit dc88178

Please sign in to comment.