Skip to content

Instantly share code, notes, and snippets.

@joevtap
Last active October 19, 2024 20:49
Show Gist options
  • Save joevtap/b7f12ca1b58d7e0db63fc9677d495d4a to your computer and use it in GitHub Desktop.
Save joevtap/b7f12ca1b58d7e0db63fc9677d495d4a to your computer and use it in GitHub Desktop.
Configurações para ambiente staging em VM na Digital Ocean (com Github Actions e Docker)
github's gist naming system sucks
APP_PORT=5000
HOST=localhost
POSTGRES_USER=dev
POSTGRES_PASSWORD=senha
PGPORT=5001
DB_USER=dev
DB_PASSWORD=senha
DB_HOST=db
DB_PORT=5001
DB_NAME=dev
DB_SCHEMA=public
DB_SSLMODE=disable
DATABASE_URL=mysql://root:senha@db:4001/banco?schema=public
JWT_SECRET=CHANGE
# mysql
MYSQL_TCP_PORT=5001
MYSQL_ROOT_PASSWORD=senha
MYSQL_DATABASE=db
services:
api:
build:
context: .
dockerfile: Dockerfile
args: ["APP_PORT=${APP_PORT}"]
env_file: [.env]
ports: ["${APP_PORT}:${APP_PORT}"]
restart: always
depends_on: [db, migrations]
migrations:
image: node:20.12-alpine
env_file: [.env]
restart: on-failure
working_dir: /migrate
volumes: [./prisma/:/migrate/prisma]
command: npx prisma migrate deploy
depends_on: [db]
db:
image: mysql:8.0.36-debian
restart: always
command: --default-authentication-plugin=mysql_native_password
env_file: [.env]
volumes: [mysqldata:/var/lib/mysql]
ports: ["127.0.0.1:${DB_PORT}:${DB_PORT}"]
volumes:
mysqldata:
# Postgre no lugar do mysql e sem service de migrations com prisma
services:
api:
build:
context: .
dockerfile: Dockerfile
args:
- APP_PORT=${APP_PORT}
ports:
- ${APP_PORT}:${APP_PORT}
env_file:
- .env
restart: always
depends_on:
- db
db:
image: postgres:16.2
restart: always
env_file:
- .env
ports:
- 127.0.0.1:${DB_PORT}:${DB_PORT}
services:
migrations:
image: node:20.12-alpine
env_file: [.env]
restart: on-failure
working_dir: /migrate
volumes: [./prisma/:/migrate/prisma]
command: npx prisma migrate deploy
depends_on: [db]
pgadmin4:
image: elestio/pgadmin:REL-8_12
restart: always
env_file: [.env]
ports: ["${PGADMIN_LISTEN_PORT}:${PGADMIN_LISTEN_PORT}"]
volumes: ["./servers.json:/pgadmin4/servers.json"]
depends_on: [db]
db:
image: postgres:16.2
restart: always
env_file: [.env]
ports: ["${PGPORT}:${PGPORT}"]
volumes: ["./pgdata:/var/lib/postgresql/data"]
# .env
#
# POSTGRES_USER="catcare"
# POSTGRES_PASSWORD="catcarepass"
# PGPORT="5432"
# PGADMIN_DEFAULT_EMAIL="[email protected]"
# PGADMIN_DEFAULT_PASSWORD="catcarepass"
# PGADMIN_LISTEN_PORT="5433"
# # Prisma ORM (change "db" to "localhost" if running on local machine and not in docker)
# DATABASE_URL="postgresql://catcare:catcarepass@db:5432/catcare?schema=public"
FROM node:21.6-alpine
WORKDIR /app
COPY . .
ARG APP_PORT
EXPOSE ${APP_PORT}
RUN ["npm", "i"]
RUN ["npm", "run", "build"]
CMD ["node", "."]
name: Staging on Digital Ocean Droplet
run-name: ${{ github.actor }} is deploying to staging environment
on:
workflow_dispatch:
push:
branches:
- staging # nome da branch que será atualizada com o github workflow
jobs:
ssh-into-droplet-and-deploy-changes:
name: SSH into droplet and deploy changes
runs-on: ubuntu-22.04
steps:
- name: SSH into droplet
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: root
password: ${{secrets.PASSWORD}}
port: ${{ secrets.PORT }}
script_stop: true
script: |
cd /home/app
git checkout staging
git pull
docker compose down
docker compose up -d --build --force-recreate --remove-orphans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment