Skip to content

Commit

Permalink
feat(backend): re-instate Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
dr460nf1r3 committed Jun 24, 2024
1 parent d64a639 commit d497b09
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 5 deletions.
42 changes: 42 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# compiled output
dist
tmp
/out-tsc

# dependencies
node_modules

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings

# System Files
.DS_Store
Thumbs.db

.nx/cache
.nx/workspace-data

.angular
44 changes: 44 additions & 0 deletions .github/workflows/publish-dockerfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Create and publish a Docker image for the backend
on:
push:
branches: [ "main" ]

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

jobs:
build-and-push-backend:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
9 changes: 6 additions & 3 deletions backend/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# Tdlib requires glibc, therefore alpine can't be used
FROM node:22-bookworm-slim AS builder

WORKDIR /build
COPY . /build

# Enable the use of pnpm and compile the backend
RUN corepack enable && corepack prepare pnpm@latest --activate
RUN pnpm install
RUN pnpm build
RUN pnpx nx run backend:build

FROM node:22-bookworm-slim

# Copy the compiled backend and the entry point script in a clean image
WORKDIR /app
COPY ./entry_point.sh /entry_point.sh
COPY entry_point.sh /entry_point.sh
RUN chmod +x /entry_point.sh
COPY --from=builder /build/dist /app
COPY --from=builder /build/dist/backend /app
COPY --from=builder /build/node_modules /app/node_modules

EXPOSE 3000
Expand Down
5 changes: 5 additions & 0 deletions backend/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"projectType": "application",
"tags": [],
"targets": {
"build": {
"options": {
"generatePackageJson": true
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
Expand Down
File renamed without changes.
9 changes: 7 additions & 2 deletions shared-lib/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"outputs": [
"{options.outputPath}"
],
"options": {
"outputPath": "dist/shared-lib",
"main": "shared-lib/src/index.ts",
"tsConfig": "shared-lib/tsconfig.lib.json",
"assets": ["shared-lib/*.md"]
"assets": [
"shared-lib/*.md"
],
"generatePackageJson": true
}
}
}
Expand Down

0 comments on commit d497b09

Please sign in to comment.