Skip to content

Commit

Permalink
Add Docker workflow and update build process
Browse files Browse the repository at this point in the history
Introduced a new GitHub Actions workflow to automatically build and push Docker images for the application. The workflow triggers on pushes to main branch, tag creation, or manual dispatch. It checks for changes in specific paths before proceeding with the build.

Updated .gitignore to ignore .turbo files.

Modified Dockerfile of the currencia app to include DATABASE_URL as an argument and environment variable. Also adjusted the build steps and added installation of curl.

Adjusted nuxt.config.ts file to allow setting NITRO_PRESET from environment variables.

Updated docker-compose.local.yml file to include database service configuration for local development.

Added a new script "build:app" in package.json for building only the currencia app.
  • Loading branch information
HugoRCD committed Nov 14, 2024
1 parent d6d3272 commit d0839b2
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 5 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/build-app-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build and Push Application Docker Image

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

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
check-changes:
runs-on: ubuntu-latest
outputs:
src: ${{ steps.changes.outputs.src }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Check if there are changes
uses: dorny/paths-filter@v3
id: changes
with:
filters: |
src:
- 'apps/docs/**'
- 'packages/nuxt/**'
- 'packages/utils/**'
- 'bun.lockb'
build-and-push:
needs: check-changes
if: needs.check-changes.outputs.src == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

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

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,format=long
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./apps/currencia/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
TURBO_TEAM=${{ vars.TURBO_TEAM }}
TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}
DATABASE_URL=${{ secrets.DATABASE_URL }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ logs
# Local env files
.env
.vercel
.turbo
9 changes: 6 additions & 3 deletions apps/currencia/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Stage 1: Build Stage
FROM oven/bun:latest AS build

ARG DATABASE_URL
ARG TURBO_TEAM
ARG TURBO_TOKEN

ENV DATABASE_URL=$DATABASE_URL
ENV TURBO_TEAM=$TURBO_TEAM
ENV TURBO_TOKEN=$TURBO_TOKEN
ENV NODE_ENV=production
Expand All @@ -19,16 +21,17 @@ COPY . .

RUN bun install

RUN bun run dev:prepare

RUN bun run build:docs
RUN bun run build:app

# Stage 2: Final Stage
FROM oven/bun:latest

WORKDIR /app

COPY --from=build /app/apps/currencia/.output .output
COPY --from=build /app/apps/currencia/prisma ./prisma

RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*

EXPOSE 3000

Expand Down
1 change: 1 addition & 0 deletions apps/currencia/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default defineNuxtConfig({
},

nitro: {
preset: process.env.NITRO_PRESET || 'bun',
prerender: {
crawlLinks: true,
routes: ['/', '/app/market'],
Expand Down
Binary file modified bun.lockb
Binary file not shown.
36 changes: 35 additions & 1 deletion docker/docker-compose.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ services:
container_name: currencia
restart: always
environment:
- NUXT_PUBLIC_SITE_URL=${NUXT_PUBLIC_SITE_URL:-http://localhost:3000}
- DATABASE_URL=${DATABASE_URL:-postgres://postgres:postgres@currencia_db:5432/postgres}
- NUXT_OAUTH_GITHUB_CLIENT_ID=${NUXT_OAUTH_GITHUB_CLIENT_ID}
- NUXT_OAUTH_GITHUB_CLIENT_SECRET=${NUXT_OAUTH_GITHUB_CLIENT_SECRET}
- NUXT_SESSION_PASSWORD=${NUXT_SESSION_PASSWORD}
- NUXT_PRIVATE_RESEND_API_KEY=${NUXT_PRIVATE_RESEND_API_KEY}
depends_on:
- currencia_db
ports:
- "3000:3000"
healthcheck:
Expand All @@ -27,3 +33,31 @@ services:
reservations:
cpus: '0.5'
memory: 512M
currencia_db:
image: postgres:15.4
container_name: currencia_db
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
ports:
- "5436:5432"
healthcheck:
test: [ "CMD", "pg_isready", "-U", "postgres" ]
interval: 30s
timeout: 10s
retries: 3
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
deploy:
resources:
limits:
cpus: '1'
memory: 1G
reservations:
cpus: '0.5'
memory: 512M
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dev": "turbo dev --filter=@currencia/app",
"run:scripts": "turbo dev --filter='./scripts/*'",
"build": "turbo build",
"build:app": "turbo build --filter=@currencia/app",
"test": "turbo test",
"dev:prepare": "turbo dev:prepare",
"lint": "turbo lint",
Expand All @@ -18,8 +19,9 @@
"dependencies": {
"@hrcd/eslint-config": "^2.1.1",
"eslint": "^9.14.0",
"turborepo": "^0.0.1"
"turbo": "^2.2.3"
},
"packageManager": "bun@1.1.34",
"workspaces": [
"apps/*",
"packages/*",
Expand Down

0 comments on commit d0839b2

Please sign in to comment.