38 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Docker
		
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Docker
		
	
	
| # syntax = docker/dockerfile:1.2
 | |
| 
 | |
| # We use a multi-stage build to end up with a very small final image
 | |
| FROM alpine:latest AS builder
 | |
| 
 | |
| ENV PATH "$PATH:/root/.cargo/bin"
 | |
| 
 | |
| WORKDIR /usr/src/app
 | |
| 
 | |
| # Install build dependencies, rustup & rust's nightly build & toolchain
 | |
| RUN apk update && apk add --no-cache openssl-dev build-base curl && \
 | |
|     { curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly; }
 | |
| 
 | |
| # Copy source code over to builder
 | |
| COPY Cargo.toml Cargo.lock ./
 | |
| COPY src/ ./src/
 | |
| 
 | |
| # Run the tests, don't want no broken docker image
 | |
| # And then finally, build the project
 | |
| # Thank the lords that this article exists
 | |
| # https://users.rust-lang.org/t/sigsegv-with-program-linked-against-openssl-in-an-alpine-container/52172
 | |
| # TODO add what these flags do & why they work
 | |
| # NOTE: cargo install auto-appends bin to the path
 | |
| RUN --mount=type=cache,target=/usr/src/app/target RUSTFLAGS="-C target-feature=-crt-static" cargo test && \
 | |
|     RUSTFLAGS="-C target-feature=-crt-static" cargo install --path . --bin fej --root /usr/local
 | |
| 
 | |
| 
 | |
| # Now, we create the actual image
 | |
| FROM alpine:latest
 | |
| 
 | |
| # Install some dynamic libraries needed for everything to work
 | |
| RUN apk update && apk add --no-cache openssl libgcc
 | |
| 
 | |
| # Copy binary over to final image
 | |
| COPY --from=builder /usr/local/bin/fej /usr/local/bin/fej
 | |
| 
 | |
| CMD ["/usr/local/bin/fej"]
 |