From 597a82ddf08b71c54ac0fdb61158b2bc035898a2 Mon Sep 17 00:00:00 2001 From: Sayan Date: Thu, 19 Nov 2020 16:31:42 +0530 Subject: [PATCH] Use binary for building docker image (#40) * Use binary for building docker image In the previous workflow, we were building and testing twice: once for the docker image and once for the test step. Now, we'll build a debug version in the test step, then build a release version and finally copy that into the docker image. This would heavily reduce our build times. * Ignore specific files in target to speed up builds * Build image only when pushed to next or tagged * Fix build condition Since both conditions have to evaluate to true, we'll need to use refs while also matching against both `push` and `tag` events Signed-off-by: Sayan Nandan --- .ci.yml | 25 +++++++++++++++++++------ .dockerignore | 9 +++++++++ Dockerfile | 15 +++------------ 3 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 .dockerignore diff --git a/.ci.yml b/.ci.yml index 7486e8e3..a2a9256c 100644 --- a/.ci.yml +++ b/.ci.yml @@ -8,13 +8,19 @@ steps: - cargo build --verbose - cargo test --verbose ---- -kind: pipeline -type: docker -name: Docker Image + - name: build-docker-binary + image: rust + commands: + - cargo build --release + when: + ref: + - refs/heads/next + - refs/tags/* + event: + - tag + - push -steps: - - name: Push to Docker Hub + - name: push-docker-image image: plugins/docker settings: repo: terrabasedb/tdb @@ -23,3 +29,10 @@ steps: password: from_secret: docker_password auto_tag: true + when: + ref: + - refs/heads/next + - refs/tags/* + event: + - tag + - push diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..f5f755b1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +# Ignore deps in the target directory +target/debug/deps/ +target/debug/incremental/ +target/debug/build/ +target/release/deps/ +target/release/incremental/ +target/release/build/ +target/doc/ +target/rls/ diff --git a/Dockerfile b/Dockerfile index aba2329a..9aad0697 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,18 +2,9 @@ # The Dockerfile for the TerrabaseDB server tdb # -FROM rust:latest -RUN \ - apt-get update && apt-get install git curl -y && \ - cd /tmp && \ - git clone https://github.com/terrabasedb/terrabasedb.git && \ - cd terrabasedb && \ - git checkout next && \ - cargo test --release -p tdb && \ - cargo build --release -p tdb && \ - apt-get remove git curl -y && \ - apt-get autoremove -y && \ - cp -f target/release/tdb /usr/local/bin +FROM debian:stable + +COPY target/release/tdb /usr/local/bin CMD ["tdb", "-h", "0.0.0.0", "-p", "2003"]