Skip to content

Commit

Permalink
ci: deployment (#15)
Browse files Browse the repository at this point in the history
* feat(logger): add logger

* ci(build): add docker file and readme for production

* fix(logger): remove global

* ci(build): add github action for building image

* revert(build): revert add port
  • Loading branch information
khajornritdacha authored Dec 28, 2024
1 parent 39de879 commit a3ab8df
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 563 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: build-deploy

on:
workflow_dispatch:
push:
branches:
- main
tags:
- v*

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
SERVICE_NAME: larngear24-passport-backend

jobs:
build:
name: build
runs-on: ubuntu-22.04

permissions:
contents: write
packages: write
attestations: write
id-token: write

steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"

- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY}}/${{env.IMAGE_NAME}}

- name: Build and Push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels}}
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM oven/bun AS base
FROM oven/bun:1.1.34 AS base
WORKDIR /app


Expand All @@ -8,11 +8,11 @@ WORKDIR /app
# Cache packages installation
COPY package.json package.json
COPY bun.lockb bun.lockb
COPY ./prisma ./prisma/

RUN bun install

COPY prisma ./prisma/
COPY ./src ./src
COPY . .

ENV NODE_ENV=production
RUN bun run build
Expand All @@ -26,10 +26,10 @@ WORKDIR /app
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/package.json package.json
COPY --from=build /app/dist/ ./dist
COPY --from=build /app/prisma ./prisma
COPY --from=build /app/prisma/ ./prisma

ENV NODE_ENV=production

EXPOSE 3000
EXPOSE 3030

CMD ["bun", "run" , "start:migrate:prod"]
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bun install
bun run dev
```

Open <http://localhost:3000/> with your browser to see the result.
Open <http://localhost:3030/> with your browser to see the result.

### To delete database and start from scratch

Expand All @@ -66,3 +66,25 @@ docker compose -f ./docker/docker-compose.dev.yaml down
docker volume rm lg24-passport-backend_pg-data lg24-passport-backend_pgadmin-data
docker compose -f ./docker/docker-compose.dev.yaml up -d
```

## Production

### To build and run docker container locally

```bash
docker buildx build -t lg-passport-backend:0.0.1 .
```

```bash
docker run --name backend -p <PORT>:3030 -e DATABASE_URL="postgresql://<POSTGRES_USER>:<POSTGRES_PASSWORD>@<DB_HOSTNAME>:5432/<DATABASE_NAME>?schema=public" lg-passport-backend:0.0.1
```

If docker is run outside of the network of the database, make sure to add the container to the network with `--network`. Thus, the run command will look like:

```bash
docker run --name backend -p <PORT>:3030 --network <NETWORK_NAME> -e DATABASE_URL="postgresql://<POSTGRES_USER>:<POSTGRES_PASSWORD>@<DB_HOSTNAME>:5432/<DATABASE_NAME>?schema=public" lg-passport-backend:0.0.1
```

### Seed the database

There are 3 tables that need to be seeded: `Members`, `Dress`, and `Items`. To seed the database, open the pg admin and import the data from the csv files and upload them to the database directly.
Binary file modified bun.lockb
Binary file not shown.
Loading

0 comments on commit a3ab8df

Please sign in to comment.