-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile
63 lines (49 loc) · 2.58 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
63
################
##### Builder
FROM rust:1.84.0-slim@sha256:f9a7f12aebdd20234e6ef881ce009aaf14ced90d244239b975faba5e26dc0bc2 as builder
RUN rustup target add x86_64-unknown-linux-musl &&\
apt update && \
apt install -y musl-tools musl-dev && \
update-ca-certificates
WORKDIR /usr/src
# Create blank project
RUN USER=root cargo new openstack
# We want dependencies cached, so copy those first.
COPY Cargo.toml Cargo.lock /usr/src/openstack/
COPY openstack_sdk/Cargo.toml /usr/src/openstack/openstack_sdk/
COPY openstack_cli/Cargo.toml /usr/src/openstack/openstack_cli/
COPY openstack_tui/Cargo.toml /usr/src/openstack/openstack_tui/
COPY structable_derive/Cargo.toml /usr/src/openstack/structable_derive/
COPY xtask/Cargo.toml /usr/src/openstack/xtask/
COPY fuzz/Cargo.toml /usr/src/openstack/fuzz/
RUN mkdir -p openstack/openstack_cli/src/bin && touch openstack/openstack_cli/src/lib.rs &&\
cp openstack/src/main.rs openstack/openstack_cli/src/bin/osc.rs &&\
mkdir -p openstack/openstack_sdk/src && touch openstack/openstack_sdk/src/lib.rs &&\
mkdir -p openstack/structable_derive/src && touch openstack/structable_derive/src/lib.rs &&\
mkdir -p /usr/src/openstack/xtask/src && touch openstack/xtask/src/lib.rs &&\
mkdir -p openstack/fuzz/src && touch openstack/fuzz/src/lib.rs &&\
mkdir -p openstack/openstack_sdk/examples &&\
touch openstack/openstack_sdk/examples/query_find.rs &&\
touch openstack/openstack_sdk/examples/paged.rs &&\
touch openstack/openstack_sdk/examples/query.rs &&\
touch openstack/openstack_sdk/examples/ignore.rs
# Set the working directory
WORKDIR /usr/src/openstack
RUN rm -rf src
## Install target platform (Cross-Compilation) --> Needed for Alpine
RUN rustup target add x86_64-unknown-linux-musl
## This is a dummy build to get the dependencies cached.
RUN cargo build --target x86_64-unknown-linux-musl --release -p openstack_cli
# Now copy in the rest of the sources
COPY . /usr/src/openstack/
## Touch main.rs to prevent cached release build
RUN touch openstack_sdk/src/lib.rs && touch openstack_cli/src/bin/osc.rs && touch openstack_cli/src/lib.rs && touch structable_derive/src/lib.rs
# This is the actual application build.
RUN cargo build --target x86_64-unknown-linux-musl --release -p openstack_cli
################
##### Runtime
FROM alpine:3.21.2@sha256:56fa17d2a7e7f168a043a2712e63aed1f8543aeafdcee47c58dcffe38ed51099 AS runtime
LABEL maintainer="Artem Goncharov"
RUN apk add --no-cache bash
# Copy application binary from builder image
COPY --from=builder /usr/src/openstack/target/x86_64-unknown-linux-musl/release/osc /usr/local/bin