-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
62 lines (50 loc) · 2.07 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# Use latest stable as default.
# When overriding, use the alpine version to ensure
# no dependency on glibc, libgcc, etc.
# Although my license is GPL-compatible, which means
# I could technically statically link against GPL-3
# code, fuck that shit. It uses dlopen to load *itself*
# at runtime so you essentially end up with two libc's
# in memory, which.. yeah no.
# I refuse to bow down to the morons at FSF.
ARG RUST_VERSION=alpine
FROM rust:${RUST_VERSION} AS build
# Install a few essential packages
# - build-base: to build jemalloc
# - musl-dev: C standard library
# - git: required by build.rs
RUN apk add --no-cache build-base=~0 musl-dev=~1 git=~2
# shell options
# -e: exit on error
# -u: error on unset variables
# -x: print each command
SHELL [ "/bin/sh", "-eux", "-c" ]
WORKDIR /usr/src/app
COPY Cargo.toml Cargo.lock ./
# Feature flags to enable
ARG FEATURES=default
ENV SQLX_OFFLINE=1 FEATURES=${FEATURES}
## Build dependencies separately to cache them
RUN mkdir src && \
echo 'fn main(){panic!("If you see this, the build broke.")}' > src/main.rs && \
cargo build --release --features ${FEATURES}
## Build the actual binary
COPY . .
RUN cargo build --release --features ${FEATURES}
####
FROM scratch
# Labels
# Reference: https://github.com/opencontainers/image-spec/blob/main/annotations.md
LABEL org.opencontainers.image.source "https://github.com/lmaotrigine/heartbeat"
LABEL org.opencontainers.image.authors "[email protected]"
LABEL org.opencontainers.image.title "heartbeat"
LABEL org.opencontainers.image.description "A service to show a live digital heartbeat (ping) on multiple devices."
LABEL org.opencontainers.image.licenses "MPL-2.0"
COPY --from=build /usr/src/app/target/release/heartbeat /.heartbeat/bin/heartbeat
ENV HEARTBEAT_HOME=/.heartbeat
# test if the binary works
RUN [ "/.heartbeat/bin/heartbeat", "--version" ]
ENTRYPOINT [ "/.heartbeat/bin/heartbeat" ]