Skip to content

Commit

Permalink
Feat/deploy (#9)
Browse files Browse the repository at this point in the history
* ♻️ Refactor: Use WORKDIR instead of USER
* Add compose.prod.yml and deploy.yml
  • Loading branch information
usatie authored Oct 22, 2023
1 parent 80ec752 commit 52e1802
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 14 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Deploy

on:
push:
branches: [ "main" ]

jobs:
deploy:
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Deploy
run: |
echo "${{ secrets.EC2_SSH_KEY }}" > ssh_key
chmod 600 ssh_key
ssh -oStrictHostKeyChecking=no -i ssh_key [email protected] "cd /home/ubuntu/pong && git checkout main && git pull origin main && make prod"
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ e2e:
.PHONY: dev
dev:
docker compose -f compose.yml -f compose.dev.yml up -d

.PHONY: prod
prod:
docker compose -f compose.yml -f compose.prod.yml up -d
14 changes: 3 additions & 11 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
FROM node:20

RUN useradd --user-group --create-home --shell /bin/false backend &&\
npm install --global npm
WORKDIR /app

ENV HOME=/home/backend
COPY package.json ./

COPY package.json $HOME/api/
RUN chown -R backend:backend $HOME/*

USER backend
WORKDIR $HOME/api
RUN npm install

CMD ["yarn", "start"]
RUN yarn install
2 changes: 1 addition & 1 deletion compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
services:
backend:
command: ["yarn", "start:dev"]
command: yarn start:dev
4 changes: 4 additions & 0 deletions compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
web:
ports:
- "80:80"
5 changes: 3 additions & 2 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ services:
backend:
build: backend
volumes:
- ./backend:/home/backend/api
- backend_node_modules:/home/backend/api/node_modules
- ./backend:/app
- backend_node_modules:/app/node_modules
command: yarn start

volumes:
backend_node_modules:

0 comments on commit 52e1802

Please sign in to comment.