Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit 1cbd070

Browse files
committed
Add dockerfile
1 parent 92eca76 commit 1cbd070

8 files changed

Lines changed: 123 additions & 10 deletions

File tree

‎.dockerignore‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/target
2+
.git
3+
.gitignore
4+
.env
5+
.env.*
6+
!.env.example
7+
README.md
8+
.vscode
9+
.DS_Store
10+
update_table.sql

‎.env‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎.env.example‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Database
2+
DATABASE_URL=postgres://openworkers:password@localhost:5432/openworkers
3+
4+
# NATS
5+
NATS_SERVERS=nats://localhost:4222
6+
NATS_CREDENTIALS=
7+
8+
# Server
9+
RUST_LOG='info,openworkers_scheduler=debug'

‎.github/workflows/docker.yml‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- dev
7+
tags:
8+
- 'v*.*.*'
9+
pull_request:
10+
branches:
11+
- main
12+
- dev
13+
14+
jobs:
15+
build:
16+
name: Build
17+
runs-on: ubuntu-24.04
18+
steps:
19+
- name: Check Out Repo
20+
uses: actions/checkout@v4
21+
- name: Docker metadata
22+
id: metadata
23+
uses: docker/metadata-action@v5
24+
with:
25+
images: |
26+
ghcr.io/${{ github.repository }}
27+
tags: |
28+
type=raw,value=latest,enable={{is_default_branch}}
29+
type=ref,event=branch
30+
type=ref,event=tag
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
- name: Login to GitHub Container Registry
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.repository_owner }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
- name: Build and push
40+
id: docker_build
41+
uses: docker/build-push-action@v5
42+
with:
43+
file: Dockerfile
44+
push: ${{ github.event_name != 'pull_request' }}
45+
tags: ${{ steps.metadata.outputs.tags }}
46+
cache-from: type=gha,scope=main
47+
cache-to: type=gha,mode=max,scope=main
48+
platforms: linux/amd64,linux/arm64

‎.gitignore‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
/target
2-
.DS_Store
2+
.DS_Store
3+
4+
# dotenv environment variable files
5+
/.env
6+
/.env.*
7+
!/.env.example

‎.sqlx/query-efd911aec58079e06e311a5aca81e7cfaa3c37f4d3aaa46bef240c80c16b0ed5.json‎

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Dockerfile‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM rust:1.91 AS builder
2+
3+
RUN mkdir -p /build
4+
5+
ENV RUST_BACKTRACE=1
6+
ENV SQLX_OFFLINE=true
7+
8+
WORKDIR /build
9+
10+
COPY . /build
11+
12+
RUN --mount=type=cache,target=$CARGO_HOME/git \
13+
--mount=type=cache,target=$CARGO_HOME/registry \
14+
--mount=type=cache,target=/build/target \
15+
cargo build --release && cp /build/target/release/openworkers-scheduler /build/output
16+
17+
FROM debian:bookworm-slim
18+
19+
RUN apt-get update \
20+
# Install ca-certificates and wget (used for healthcheck)
21+
&& apt-get install -y ca-certificates wget \
22+
&& rm -rf /var/lib/apt/lists/*
23+
24+
COPY --from=builder /build/output /usr/local/bin/openworkers-scheduler
25+
26+
CMD ["/usr/local/bin/openworkers-scheduler"]

‎src/nats.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ pub async fn nats_connect() -> Result<async_nats::Client, async_nats::ConnectErr
77
log::debug!("connecting to nats: {nats_servers}");
88

99
match std::env::var("NATS_CREDENTIALS") {
10+
// No credentials provided
11+
Err(_) => async_nats::connect(nats_servers).await,
12+
// Empty string means no credentials
13+
Ok(ref s) if s.is_empty() => async_nats::connect(nats_servers).await,
1014
Ok(credentials) => {
1115
// Decode the base64 encoded credentials
1216
let credentials: Vec<u8> = STANDARD
@@ -22,6 +26,5 @@ pub async fn nats_connect() -> Result<async_nats::Client, async_nats::ConnectErr
2226

2327
options.connect(nats_servers).await
2428
}
25-
Err(_) => async_nats::connect(nats_servers).await,
2629
}
2730
}

0 commit comments

Comments
 (0)