Skip to content

Commit

Permalink
add dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Jul 5, 2019
1 parent 58fb795 commit 484e9c3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
language: rust
cache: cargo

env:
RUSTINFRA_IMAGE_TAG: rust-log-analyzer
RUSTINFRA_REGISTRY_NAME: rust-log-analyzer
import:
- rust-lang/simpleinfra/travis-configs/docker-to-ecr.yml

script:
- cargo test
- docker build -t rust-log-analyzer .

notifications:
email: false
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This Dockerfile is composed of two steps: the first one builds the release
# binary, and then the binary is copied inside another, empty image.

#################
# Build image #
#################

FROM ubuntu:bionic AS build

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates \
curl \
build-essential \
pkg-config \
libssl-dev

# Install the currently pinned toolchain with rustup
RUN curl https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init >/tmp/rustup-init && \
chmod +x /tmp/rustup-init && \
/tmp/rustup-init -y --no-modify-path --default-toolchain stable
ENV PATH=/root/.cargo/bin:$PATH

# Build the dependencies in a separate step to avoid rebuilding all of them
# every time the source code changes. This takes advantage of Docker's layer
# caching, and it works by copying the Cargo.{toml,lock} with dummy source code
# and doing a full build with it.
WORKDIR /tmp/source
COPY Cargo.lock Cargo.toml /tmp/source/
RUN mkdir -p /tmp/source/src && \
echo "fn main() {}" > /tmp/source/src/main.rs
RUN cargo fetch
RUN cargo build --release

# Dependencies are now cached, copy the actual source code and do another full
# build. The touch on all the .rs files is needed, otherwise cargo assumes the
# source code didn't change thanks to mtime weirdness.
RUN rm -rf /tmp/source/src
COPY src /tmp/source/src
RUN find -name "*.rs" -exec touch {} \; && cargo build --release

##################
# Output image #
##################

FROM ubuntu:bionic AS binary

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates

COPY --from=build /tmp/source/target/release/rla-offline /usr/local/bin/
COPY --from=build /tmp/source/target/release/rla-server /usr/local/bin/

CMD rla-server --port 80 --index /opt/rla/index.idx --webhook-verify --ci $CI_PROVIDER

0 comments on commit 484e9c3

Please sign in to comment.