From 2e1195cf2c8c79beac1638fd57523193d35704a6 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Fri, 09 Sep 2022 02:04:09 +0100 Subject: [PATCH] Publish docker images for chartered-web/chartered-git --- .dockerignore | 4 ++++ Dockerfile | 19 ------------------- Dockerfile-git | 22 ++++++++++++++++++++++ Dockerfile-web | 22 ++++++++++++++++++++++ chartered-git/Cargo.toml | 4 ++++ chartered-web/Cargo.toml | 4 ++++ .github/workflows/docker-publish.yml | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 156 insertions(+), 19 deletions(-) diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7bdf27b 100644 --- /dev/null +++ a/.dockerignore @@ -1,0 +1,4 @@ +Dockerfile-git +Dockerfile-web +.dockerfile +target/ diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 34e3522..0000000 100644 --- a/Dockerfile +++ /dev/null @@ -1,19 +1,0 @@ -FROM rust:alpine AS builder -RUN apk add --update gcc g++ build-base alpine-sdk sqlite-dev openssl-dev postgresql-dev -WORKDIR /app -COPY . /app -RUN cargo build --release --features postgres - -FROM alpine AS chartered-git -RUN apk add --update postgresql-dev && \ - ln -s /lib/ld-musl-$(uname -m).so.1 /lib/ld-linux-$(uname -m).so.1 -WORKDIR /app -COPY --from=builder /app/target/release/chartered-git /app/chartered-git -ENTRYPOINT ["/app/chartered-git"] - -FROM alpine AS chartered-web -RUN apk add --update postgresql-dev && \ - ln -s /lib/ld-musl-$(uname -m).so.1 /lib/ld-linux-$(uname -m).so.1 -WORKDIR /app -COPY --from=builder /app/target/release/chartered-web /app/chartered-web -ENTRYPOINT ["/app/chartered-web"] diff --git a/Dockerfile-git b/Dockerfile-git new file mode 100644 index 0000000..657a646 100644 --- /dev/null +++ a/Dockerfile-git @@ -1,0 +1,22 @@ +FROM lukemathwalker/cargo-chef:latest-rust-slim-bullseye AS chef +WORKDIR /app + +FROM chef AS planner +COPY . /app +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +RUN apt update && apt install -y pkg-config make libpq-dev libssl-dev +ARG DEBIAN_FRONTEND=noninteractive +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json +COPY . /app +RUN cargo build --release --features postgres --bin chartered-git + +FROM debian:bullseye-slim +LABEL org.opencontainers.image.source https://github.com/w4/chartered +WORKDIR /app +ARG DEBIAN_FRONTEND=noninteractive +RUN apt update && apt install -y libpq-dev libssl-dev && rm -rf /var/lib/apt/lists/* +COPY --from=builder /app/target/release/chartered-git /app/chartered-git +ENTRYPOINT ["/app/chartered-git"] diff --git a/Dockerfile-web b/Dockerfile-web new file mode 100644 index 0000000..ac394c6 100644 --- /dev/null +++ a/Dockerfile-web @@ -1,0 +1,22 @@ +FROM lukemathwalker/cargo-chef:latest-rust-slim-bullseye AS chef +WORKDIR /app + +FROM chef AS planner +COPY . /app +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +RUN apt update && apt install -y pkg-config make libpq-dev libssl-dev +ARG DEBIAN_FRONTEND=noninteractive +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json +COPY . /app +RUN cargo build --release --features postgres --bin chartered-web + +FROM debian:bullseye-slim +LABEL org.opencontainers.image.source https://github.com/w4/chartered +WORKDIR /app +ARG DEBIAN_FRONTEND=noninteractive +RUN apt update && apt install -y libpq-dev libssl-dev && rm -rf /var/lib/apt/lists/* +COPY --from=builder /app/target/release/chartered-web /app/chartered-web +ENTRYPOINT ["/app/chartered-web"] diff --git a/chartered-git/Cargo.toml b/chartered-git/Cargo.toml index 2732168..d7b2317 100644 --- a/chartered-git/Cargo.toml +++ a/chartered-git/Cargo.toml @@ -36,3 +36,7 @@ tracing = "0.1" tracing-subscriber = "0.3" url = "2" + +[features] +sqlite = ["chartered-db/sqlite"] +postgres = ["chartered-db/postgres"] diff --git a/chartered-web/Cargo.toml b/chartered-web/Cargo.toml index ef875f9..d8e5973 100644 --- a/chartered-web/Cargo.toml +++ a/chartered-web/Cargo.toml @@ -40,3 +40,7 @@ tracing = "0.1" tracing-subscriber = "0.3" url = { version = "2.2", features = ["serde"] } + +[features] +sqlite = ["chartered-db/sqlite"] +postgres = ["chartered-db/postgres"] diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..0bc1756 100644 --- /dev/null +++ a/.github/workflows/docker-publish.yml @@ -1,0 +1,100 @@ +name: Create and publish Docker images + +on: + push: + branches: [ main ] + tags: [ 'v*.*.*' ] + pull_request: + branches: [ main ] + +env: + REGISTRY: ghcr.io + +jobs: + build-and-push-chartered-web: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/w4/chartered-web + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push chartered-web + id: build-and-push + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + file: ./Dockerfile-web + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + build-and-push-chartered-git: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/w4/chartered-git + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push chartered-git + id: build-and-push + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + file: ./Dockerfile-git + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} -- rgit 0.1.3