Skip to content

Commit

Permalink
Dockerize application and add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastian Oppermann committed Aug 11, 2024
1 parent 73b677f commit 3e88ec0
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: ci

on:
push:
branches:
- "**"
tags:
- "v*.*.*"

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- 1.78.0
steps:
- uses: actions/checkout@v4
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: cargo build --verbose
- run: cargo test --verbose
docker:
runs-on: ubuntu-latest
steps:
# See https://web.archive.org/web/20240729104252/https://docs.docker.com/build/ci/github-actions/manage-tags-labels/
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/Bastian/data-processor
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
# See https://web.archive.org/web/20240709084932/https://docs.github.com/en/actions/creating-actions/creating-a-docker-container-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ARG RUST_VERSION=1.79.0
ARG APP_NAME=data-processor


FROM rust:${RUST_VERSION} AS build
ARG APP_NAME
WORKDIR /app

# Build the application.
# Leverage a cache mount to /usr/local/cargo/registry/
# for downloaded dependencies, a cache mount to /usr/local/cargo/git/db
# for git repository dependencies, and a cache mount to /app/target/ for
# compiled dependencies which will speed up subsequent builds.
# Leverage a bind mount to the src directory to avoid having to copy the
# source code into the container. Once built, copy the executable to an
# output directory before the cache mounted /app/target is unmounted.
RUN --mount=type=bind,source=src,target=src \
--mount=type=bind,source=Cargo.toml,target=Cargo.toml \
--mount=type=bind,source=Cargo.lock,target=Cargo.lock \
--mount=type=cache,target=/app/target/ \
--mount=type=cache,target=/usr/local/cargo/git/db \
--mount=type=cache,target=/usr/local/cargo/registry/ \
cargo build --locked --release && \
cp ./target/release/$APP_NAME /bin/server

FROM debian:stable-slim AS final

COPY --from=build /bin/server /bin/

EXPOSE 8080

CMD ["/bin/server"]

0 comments on commit 3e88ec0

Please sign in to comment.