Skip to content

Commit 18a6065

Browse files
Adds docker image publishing (#14)
Uses envsubst in an entrypoint script to make injecting secrets (e.g. db password and access_key_secret) easier. Co-authored-by: Noah Kennedy <Nomaxx117@gmail.com>
1 parent f3db180 commit 18a6065

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

.github/workflows/on-release.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Publish Docker image
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
IMAGE_NAME: ${{ github.repository }}
10+
11+
jobs:
12+
build-and-push-image:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v3
21+
22+
- name: Log in to the Container registry
23+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
24+
with:
25+
registry: ${{ env.REGISTRY }}
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Extract metadata (tags, labels) for Docker
30+
id: meta
31+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
32+
with:
33+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
34+
35+
- name: Build and push Docker image
36+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
37+
with:
38+
context: .
39+
file: docker/Dockerfile
40+
push: true
41+
tags: ${{ steps.meta.outputs.tags }}
42+
labels: ${{ steps.meta.outputs.labels }}

docker/Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM rust:1.71-bullseye as builder
2+
WORKDIR /usr/src/freighter
3+
4+
COPY Cargo.toml .
5+
COPY Cargo.lock .
6+
COPY .cargo/ .cargo
7+
COPY freighter/ freighter
8+
COPY freighter-auth/ freighter-auth
9+
COPY freighter-index/ freighter-index
10+
COPY freighter-server/ freighter-server
11+
COPY freighter-storage/ freighter-storage
12+
13+
RUN cd freighter \
14+
&& cargo install --path .
15+
16+
FROM debian:bullseye-slim
17+
COPY --from=builder /usr/local/cargo/bin/freighter /usr/local/bin/freighter
18+
19+
RUN apt-get update \
20+
&& apt-get install -y gettext-base \
21+
&& rm -rf /var/lib/apt/lists/*
22+
23+
COPY docker/entrypoint.sh .
24+
COPY docker/config.yaml.tpl .
25+
26+
# Create file so it can be written in entrypoint
27+
RUN touch config.yaml && chown nobody:nogroup config.yaml
28+
29+
USER nobody:nogroup
30+
31+
ENTRYPOINT ["/entrypoint.sh"]

docker/config.yaml.tpl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
service:
2+
address: "$SERVER_ADDR"
3+
download_endpoint: "$DOWNLOAD_ENDPOINT"
4+
api_endpoint: "$API_ENDPOINT"
5+
metrics_address: "$METRICS_ADDR"
6+
7+
index_db: &db
8+
dbname: "$POSTGRES_DBNAME"
9+
user: "$POSTGRES_USER"
10+
password: "$POSTGRES_PASSWORD"
11+
host: "$POSTGRES_HOST"
12+
port: $POSTGRES_PORT
13+
14+
auth_db: *db
15+
16+
store:
17+
name: "$BUCKET_NAME"
18+
endpoint_url: "$BUCKET_ENDPOINT"
19+
region: "us-east-1"
20+
access_key_id: "$BUCKET_ACCESS_KEY_ID"
21+
access_key_secret: "$BUCKET_ACCESS_KEY_ID"

docker/entrypoint.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
# Freighter Server
4+
export SERVER_ADDR="${SERVER_ADDR:-127.0.0.1:3000}"
5+
export DOWNLOAD_ENDPOINT="${DOWNLOAD_ENDPOINT:-"$SERVER_ADDR/downloads/{crate}/{version}"}"
6+
export API_ENDPOINT="${API_ENDPOINT:-"$SERVER_ADDR"}"
7+
export METRICS_ADDR="${METRICS_ADDR:-127.0.0.1:3001}"
8+
9+
# PostgreSQL
10+
export POSTGRES_HOST="${POSTGRES_HOST:?\$POSTGRES_HOST required}"
11+
export POSTGRES_PORT="${POSTGRES_PORT:-5432}"
12+
export POSTGRES_USER="${POSTGRES_USER:?\$POSTGRES_USER required}"
13+
export POSTGRES_PASSWORD="${POSTGRES_PASSWORD:?\$POSTGRES_PASSWORD required}"
14+
export POSTGRES_DBNAME="${POSTGRES_DBNAME:-freighter}"
15+
16+
# S3 Storage
17+
export BUCKET_NAME="${BUCKET_NAME:?\$BUCKET_NAME required}"
18+
export BUCKET_ENDPOINT="${BUCKET_ENDPOINT:?\$BUCKET_ENDPOINT required}"
19+
export BUCKET_ACCESS_KEY_ID="${BUCKET_ACCESS_KEY_ID:?\$BUCKET_ACCESS_KEY_ID required}"
20+
export BUCKET_ACCESS_KEY_SECRET="${BUCKET_ACCESS_KEY_SECRET:?\$BUCKET_ACCESS_KEY_SECRET required}"
21+
22+
envsubst < "config.yaml.tpl" > "config.yaml"
23+
24+
exec freighter -c config.yaml

0 commit comments

Comments
 (0)