Skip to content

Commit

Permalink
Adds docker image publishing (#14)
Browse files Browse the repository at this point in the history
Uses envsubst in an entrypoint script to make injecting secrets (e.g. db
password and access_key_secret) easier.

Co-authored-by: Noah Kennedy <[email protected]>
  • Loading branch information
will118 and Noah-Kennedy authored Jul 18, 2023
1 parent f3db180 commit 18a6065
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/on-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publish Docker image

on:
release:
types: [published]

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

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

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

- 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
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
file: docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
31 changes: 31 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM rust:1.71-bullseye as builder
WORKDIR /usr/src/freighter

COPY Cargo.toml .
COPY Cargo.lock .
COPY .cargo/ .cargo
COPY freighter/ freighter
COPY freighter-auth/ freighter-auth
COPY freighter-index/ freighter-index
COPY freighter-server/ freighter-server
COPY freighter-storage/ freighter-storage

RUN cd freighter \
&& cargo install --path .

FROM debian:bullseye-slim
COPY --from=builder /usr/local/cargo/bin/freighter /usr/local/bin/freighter

RUN apt-get update \
&& apt-get install -y gettext-base \
&& rm -rf /var/lib/apt/lists/*

COPY docker/entrypoint.sh .
COPY docker/config.yaml.tpl .

# Create file so it can be written in entrypoint
RUN touch config.yaml && chown nobody:nogroup config.yaml

USER nobody:nogroup

ENTRYPOINT ["/entrypoint.sh"]
21 changes: 21 additions & 0 deletions docker/config.yaml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
service:
address: "$SERVER_ADDR"
download_endpoint: "$DOWNLOAD_ENDPOINT"
api_endpoint: "$API_ENDPOINT"
metrics_address: "$METRICS_ADDR"

index_db: &db
dbname: "$POSTGRES_DBNAME"
user: "$POSTGRES_USER"
password: "$POSTGRES_PASSWORD"
host: "$POSTGRES_HOST"
port: $POSTGRES_PORT

auth_db: *db

store:
name: "$BUCKET_NAME"
endpoint_url: "$BUCKET_ENDPOINT"
region: "us-east-1"
access_key_id: "$BUCKET_ACCESS_KEY_ID"
access_key_secret: "$BUCKET_ACCESS_KEY_ID"
24 changes: 24 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

# Freighter Server
export SERVER_ADDR="${SERVER_ADDR:-127.0.0.1:3000}"
export DOWNLOAD_ENDPOINT="${DOWNLOAD_ENDPOINT:-"$SERVER_ADDR/downloads/{crate}/{version}"}"
export API_ENDPOINT="${API_ENDPOINT:-"$SERVER_ADDR"}"
export METRICS_ADDR="${METRICS_ADDR:-127.0.0.1:3001}"

# PostgreSQL
export POSTGRES_HOST="${POSTGRES_HOST:?\$POSTGRES_HOST required}"
export POSTGRES_PORT="${POSTGRES_PORT:-5432}"
export POSTGRES_USER="${POSTGRES_USER:?\$POSTGRES_USER required}"
export POSTGRES_PASSWORD="${POSTGRES_PASSWORD:?\$POSTGRES_PASSWORD required}"
export POSTGRES_DBNAME="${POSTGRES_DBNAME:-freighter}"

# S3 Storage
export BUCKET_NAME="${BUCKET_NAME:?\$BUCKET_NAME required}"
export BUCKET_ENDPOINT="${BUCKET_ENDPOINT:?\$BUCKET_ENDPOINT required}"
export BUCKET_ACCESS_KEY_ID="${BUCKET_ACCESS_KEY_ID:?\$BUCKET_ACCESS_KEY_ID required}"
export BUCKET_ACCESS_KEY_SECRET="${BUCKET_ACCESS_KEY_SECRET:?\$BUCKET_ACCESS_KEY_SECRET required}"

envsubst < "config.yaml.tpl" > "config.yaml"

exec freighter -c config.yaml

0 comments on commit 18a6065

Please sign in to comment.