Skip to content

Commit 952a311

Browse files
committed
Add dockerfile
1 parent c5a5700 commit 952a311

9 files changed

Lines changed: 178 additions & 24 deletions

File tree

.dockerignore

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Dependencies
2+
node_modules
3+
4+
# Build output
5+
dist
6+
*.log
7+
8+
# Environment files
9+
.env
10+
.env.*
11+
!.env.example
12+
13+
# Git
14+
.git
15+
.gitignore
16+
.gitattributes
17+
18+
# IDE
19+
.vscode
20+
.idea
21+
*.swp
22+
*.swo
23+
*~
24+
25+
# OS
26+
.DS_Store
27+
Thumbs.db
28+
29+
# Testing
30+
coverage
31+
*.test.ts
32+
*.spec.ts
33+
34+
# Documentation
35+
*.md
36+
!package.json
37+
38+
# CI/CD
39+
.github
40+
.gitlab-ci.yml
41+
42+
# Docker
43+
Dockerfile
44+
.dockerignore
45+
docker-compose*.yml
46+
47+
# Claude
48+
.claude
49+
CLAUDE.md

.env.example

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Database
2-
DB_HOST=localhost
3-
DB_PORT=5432
4-
DB_USER=postgres
5-
DB_PASSWORD=password
6-
DB_NAME=openworkers
2+
POSTGRES_HOST=localhost
3+
POSTGRES_PORT=5432
4+
POSTGRES_USER=postgres
5+
POSTGRES_PASSWORD=password
6+
POSTGRES_DB=openworkers
77

88
# JWT (must be at least 32 characters)
99
JWT_ACCESS_SECRET=your-secret-key-here-must-be-at-least-32-chars-long
@@ -18,3 +18,6 @@ GITHUB_CLIENT_SECRET=your-github-oauth-app-client-secret
1818
# Server
1919
PORT=7000
2020
NODE_ENV=development
21+
22+
# Engine
23+
ENGINE_URL=http://localhost:8080

.github/workflows/docker.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Docker Build and Push
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- "v*"
9+
pull_request:
10+
branches:
11+
- main
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
IMAGE_NAME: ${{ github.repository }}
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3
30+
31+
- name: Log in to Container Registry
32+
if: github.event_name != 'pull_request'
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ${{ env.REGISTRY }}
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Extract metadata
40+
id: meta
41+
uses: docker/metadata-action@v5
42+
with:
43+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
44+
tags: |
45+
type=ref,event=branch
46+
type=ref,event=pr
47+
type=semver,pattern={{version}}
48+
type=semver,pattern={{major}}.{{minor}}
49+
type=semver,pattern={{major}}
50+
type=sha,prefix={{branch}}-
51+
type=raw,value=latest,enable={{is_default_branch}}
52+
53+
- name: Build and push
54+
uses: docker/build-push-action@v5
55+
with:
56+
context: .
57+
platforms: linux/amd64,linux/arm64
58+
push: ${{ github.event_name != 'pull_request' }}
59+
tags: ${{ steps.meta.outputs.tags }}
60+
labels: ${{ steps.meta.outputs.labels }}
61+
cache-from: type=gha
62+
cache-to: type=gha,mode=max

.gitignore

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ _.log
1616
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
1717

1818
# dotenv environment variable files
19-
.env
20-
.env.development.local
21-
.env.test.local
22-
.env.production.local
23-
.env.local
19+
/.env
20+
/.env.*
21+
!/.env.example
2422

2523
# caches
2624
.eslintcache

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"cSpell.words": ["openworkers"]
2+
"cSpell.words": ["buildx", "croner", "healthcheck", "openworkers"]
33
}

Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM oven/bun:1.3.3-alpine AS installer
2+
3+
RUN mkdir -p /build
4+
5+
WORKDIR /build
6+
7+
## Copy package files
8+
COPY bun.lock /build/
9+
COPY package.json /build/
10+
11+
## Install dependencies
12+
RUN bun install --frozen-lockfile
13+
14+
# Source Image
15+
FROM installer AS sources
16+
17+
## Copy sources
18+
COPY src /build/src
19+
COPY examples /build/examples
20+
COPY tsconfig.json /build/tsconfig.json
21+
22+
# Builder Image
23+
FROM sources AS builder
24+
25+
WORKDIR /build
26+
RUN bun compile
27+
28+
# Final image
29+
FROM alpine:3.22
30+
31+
RUN apk add --no-cache libstdc++ libgcc
32+
33+
WORKDIR /build
34+
35+
COPY --from=builder /build/dist /build/dist
36+
COPY --from=builder /build/node_modules/@openworkers/croner-wasm/dist/node node_modules/@openworkers/croner-wasm/dist/node
37+
38+
EXPOSE 7000
39+
40+
CMD [ "./dist/openworkers-api" ]

src/config/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ function loadConfig(): Config {
5858
nodeEnv: process.env.NODE_ENV,
5959
port: process.env.PORT,
6060
database: {
61-
host: process.env.DB_HOST,
62-
port: process.env.DB_PORT,
63-
user: process.env.DB_USER,
64-
password: process.env.DB_PASSWORD,
65-
name: process.env.DB_NAME,
61+
host: process.env.POSTGRES_HOST,
62+
port: process.env.POSTGRES_PORT,
63+
user: process.env.POSTGRES_USER,
64+
password: process.env.POSTGRES_PASSWORD,
65+
name: process.env.POSTGRES_DB,
6666
},
6767
jwt: {
6868
access: {

src/services/db/client.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { database } from "../../config";
33

44
// Initialize DB connection
55
export const sql = new SQL({
6-
host: database.host,
7-
port: database.port,
8-
user: database.user,
9-
password: database.password,
10-
database: database.name,
11-
adapter: "postgres",
12-
max: 10,
6+
host: database.host,
7+
port: database.port,
8+
user: database.user,
9+
password: database.password,
10+
database: database.name,
11+
adapter: "postgres",
12+
max: 10,
1313
});

src/services/db/environments.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { sql } from "./client";
22
import type { IEnvironment, IEnvironmentValue } from "../../types";
33

44
// Environments
5-
export async function findAllEnvironments(userId: string): Promise<IEnvironment[]> {
5+
export async function findAllEnvironments(
6+
userId: string
7+
): Promise<IEnvironment[]> {
68
return sql`
79
SELECT
810
e.id,

0 commit comments

Comments
 (0)