Skip to content

Commit

Permalink
Setup Digital Ocean (#436)
Browse files Browse the repository at this point in the history
* init setup digital ocean

* split script

* add echo secret_key

* add echo secret_key

* update droplet_ip

* Add DigitalOcean droplet to known_hosts
  • Loading branch information
omarciovsena authored Jun 3, 2024
1 parent fc31798 commit 901c2e7
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 22 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Deploy to DigitalOcean

on:
push:
branches:
- config/digital-ocean

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup SSH and known hosts
uses: webfactory/ssh-agent@v0.5.3
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Add DigitalOcean droplet to known_hosts
run: ssh-keyscan ${{ secrets.DROPLET_IP }} >> ~/.ssh/known_hosts

- name: Copy project files to the server
run: rsync -avz --exclude '/node_modules/' --exclude '/.git/' ./ root@${{ secrets.DROPLET_IP }}:/root/abibliadigital/

- name: Build container
run: ssh root@${{ secrets.DROPLET_IP }} "cd /root/abibliadigital/ && docker-compose up -d --build"

- name: Environment setup
run: |
ssh root@${{ secrets.DROPLET_IP }} "echo 'MONGODB_URI=${{ secrets.MONGODB_URI }}' >> /root/abibliadigital/.env"
ssh root@${{ secrets.DROPLET_IP }} "echo 'SECRET_KEY=${{ secrets.SECRET_KEY }}' >> /root/abibliadigital/.env"
ssh root@${{ secrets.DROPLET_IP }} "echo 'SENDGRID_KEY=${{ secrets.SENDGRID_KEY }}' >> /root/abibliadigital/.env"
- name: Restart the application
run: ssh root@${{ secrets.DROPLET_IP }} "cd /root/abibliadigital/ && docker-compose down && docker-compose up -d"
2 changes: 1 addition & 1 deletion docker-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# specify the node base image with your desired version node:<version>
FROM node:10.14.0
FROM node:16.20.1
# replace this with your application's default port
EXPOSE 4201
EXPOSE 49153
Expand Down
44 changes: 44 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: '3'

services:
abibliadigital:
build: ./docker-api
command: [ "bash", "/usr/src/api/start.sh" ]
ports:
- "3000:3000"
expose:
- "3000"
container_name: abibliadigital
environment:
- MONGODB_URI=mongodb://abibliadigital-mongo/abibliadigital
- NODE_ENV=development
- SECRET_KEY=19B2AFFC3B287A4E41FA7C1158A8A
- REDIS_URL=redis://abibliadigital-redis
volumes:
- ../abibliadigital:/usr/src/api
depends_on:
- abibliadigital-mongo
- abibliadigital-redis

abibliadigital-mongo:
build: ./docker-mongo
container_name: abibliadigital-mongo
ports:
- "27017:27017"
expose:
- "27017"
volumes:
- ../mongo-abibliadigital/db/data:/data/db
- ../mongo-abibliadigital/db/log:/var/log/mongodb

abibliadigital-redis:
image: "redis:alpine"
container_name: abibliadigital-redis
command: redis-server
ports:
- "6379:6379"
expose:
- "6379"
restart: always
volumes:
- ../redis-data:/var/lib/redis
21 changes: 2 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
version: '3'

services:
abibliadigital:
abibliadigital-app:
build: ./docker-api
command: [ "bash", "/usr/src/api/start.sh" ]
ports:
- "3000:3000"
expose:
- "3000"
container_name: abibliadigital
environment:
- MONGODB_URI=mongodb://abibliadigital-mongo/abibliadigital
- NODE_ENV=development
- SECRET_KEY=19B2AFFC3B287A4E41FA7C1158A8A
- REDIS_URL=redis://abibliadigital-redis
container_name: abibliadigital-app
volumes:
- ../abibliadigital:/usr/src/api
depends_on:
- abibliadigital-mongo
- abibliadigital-redis

abibliadigital-mongo:
build: ./docker-mongo
container_name: abibliadigital-mongo
ports:
- "27017:27017"
expose:
- "27017"
volumes:
- ../mongo-abibliadigital/db/data:/data/db
- ../mongo-abibliadigital/db/log:/var/log/mongodb

abibliadigital-redis:
image: "redis:alpine"
container_name: abibliadigital-redis
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "MIT",
"private": false,
"engines": {
"node": ">=10.14.0"
"node": ">=16.20.1"
},
"scripts": {
"dev": "nodemon --exec babel-node app.js",
Expand Down
2 changes: 1 addition & 1 deletion start.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
yarn install
yarn dev
yarn start

0 comments on commit 901c2e7

Please sign in to comment.