Skip to content

Commit

Permalink
add CARGOPROFILE to build dev or release profile binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
John Petterson committed Jan 6, 2024
1 parent e2a441c commit 713da17
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM docker.io/rust:1.66-alpine as builder
ARG CRATESIOMIRROR
ARG CRATESIOMIRROR=
ARG CARGOPROFILE=release
RUN apk add --no-cache musl-dev protoc protobuf-dev

WORKDIR /usr/src/app
Expand All @@ -11,10 +12,10 @@ RUN if [ -z "$CRATESIOMIRROR" ]; then exit 0; fi; \
# Cache rust dependencies
# https://stackoverflow.com/questions/58473606/cache-rust-dependencies-with-docker-build
COPY ./rust-toolchain* ./Cargo.* ./
RUN mkdir ./src && echo 'fn main() { println!("Dummy!"); }' > ./src/main.rs && cargo build --release && rm -rf ./src
RUN mkdir ./src && echo 'fn main() { println!("Dummy!"); }' > ./src/main.rs && cargo build --profile "$CARGOPROFILE" && rm -rf ./src

COPY ./ ./
RUN cargo install --frozen --offline --path .
RUN cargo install --frozen --offline --profile "$CARGOPROFILE" --path .

FROM docker.io/alpine:3.18
COPY --from=builder /usr/local/cargo/bin/zkc_state_manager /usr/local/bin/myapp
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ services:
build:
context: ./services/auth
args:
- GOPROXY=${GOPROXY}
- GOPROXY=${GOPROXY:-}
environment:
- MONGODB_URI=mongodb://${MONGODB_USERNAME:-root}:${MONGODB_PASSWORD:-OlQtOieOzHMSfaEaEZrkd}@mongodb:27017

kvpair:
build:
context: .
args:
- CRATESIOMIRROR=${CRATESIOMIRROR}
- CRATESIOMIRROR=${CRATESIOMIRROR:-}
- CARGOPROFILE=${CARGOPROFILE:-}
ports:
- 50051:50051
environment:
Expand Down
2 changes: 1 addition & 1 deletion services/auth/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM docker.io/golang:1.20-alpine as builder

WORKDIR /app
ARG GOPROXY
ARG GOPROXY=

COPY server ./server
COPY go.mod go.sum ./
Expand Down

0 comments on commit 713da17

Please sign in to comment.