Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ HOSTNAME='localhost'
PORT=3000
SECRET_KEY='321'
DATABASE_URL="postgresql://postgres:password@localhost:5432/octopost"

DB_USER='postgres'
DB_PASSWORD='password'
DB_NAME='octopost'
13 changes: 9 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Build and Test
on:
pull_request:
branches: ['main']
push:
branches: ['main']

jobs:
test:
Expand Down Expand Up @@ -34,8 +36,11 @@ jobs:
- name: Code Checkout
uses: actions/checkout@v3

- name: Setup deps
uses: ./.github/actions/install-deps
- name: Create .env
run: cp .env.example .env

- name: Run docker-compose in prod profile
run: docker compose --profile prod up --build -d

- name: Build
run: pnpm build
- name: Check Docker Containers
run: docker compose ps --services | xargs -I {} sh -c 'docker compose ps {} | grep "Up" || exit 1'
2 changes: 2 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Code Style
on:
pull_request:
branches: ['main']
push:
branches: ['main']

jobs:
code-style:
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Docker Push

on:
push:
branches:
- main
pull_request:
branches:
- main
# workflow_run:
# workflows: ['Build and Test']
# types:
# - completed
jobs:
push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Log into Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}

- name: Build and push Docker image
run: |
SHA=${{ github.sha }}
docker build -t devhatt/octopost-backend:$SHA .
docker push devhatt/octopost-backend:$SHA
docker tag devhatt/octopost-backend:$SHA devhatt/octopost-backend:latest
docker push devhatt/octopost-backend:latest
6 changes: 3 additions & 3 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ save-workspace-protocol=rolling
# pnpm will automatically install the specified version of Node.js and use it
# for running pnpm run commands or the pnpm node command.
# https://pnpm.io/npmrc#save-workspace-protocol
use-node-version=22.0.0
use-node-version=20.15.1

# Prevent contributors of your project from adding new incompatible dependencies
# This way, even if someone is using Node.js v16, they will not be able to install
# a new dependency that doesn't support Node.js v22.0.0.
# a new dependency that doesn't support Node.js v20.15.1.
# https://pnpm.io/npmrc#use-node-version
node-version=22.0.0
node-version=20.15.1
engine-strict=true


Expand Down
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ RUN pnpm build
FROM node:22-alpine3.19

WORKDIR /usr/src/app
RUN npm install -g pnpm@8
COPY --from=build /usr/src/app/package.json ./package.json
COPY --from=build /usr/src/app/build ./build
COPY --from=build /usr/src/app/node_modules ./node_modules

EXPOSE 3000

CMD ["pnpm", "run", "start"]
CMD ["cross-env", "MODE=PROD", "node", "build/index.js"]
14 changes: 10 additions & 4 deletions docker-compose.yaml → compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ services:
ports:
- '5432:5432'
environment:
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: 'password'
POSTGRES_DB: 'octopost'
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_NAME}
PGDATA: '/var/lib/postgresql/mydata'
env_file:
- .env.example
- .env
volumes:
- db:/var/lib/postgresql/mydata
networks:
Expand All @@ -24,9 +27,12 @@ services:
profiles:
- prod
ports:
- 3000:3000
- ${PORT}:${PORT}
depends_on:
- db-prod
env_file:
- .env.example
- .env
networks:
- octopost

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"private": true,
"engines": {
"node": "22",
"node": "20.15.1",
"pnpm": "8"
},
"scripts": {
Expand Down
Loading