From 4ad44b39b37b0f3439c5b7735ca4ac1df47fb35c Mon Sep 17 00:00:00 2001 From: realaravinth Date: Thu, 16 Dec 2021 14:51:51 +0530 Subject: [PATCH] Fixes #2: fix docker builds Docker layer caching broke the build. target/release/libcache.so that was copied over from "builder" stage img was the result of the first stage of compilation(dependencies only and no source code) So the object file didn't contain anything that resembled this repo's source code. This patch employs a slightly modified caching technique(see Dockerfile) which fixes the issue --- .github/workflows/linux.yml | 29 +++++++++++++++-------------- Dockerfile | 11 ++++------- Makefile | 8 +++----- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 39a6be7..6ee4980 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -37,22 +37,23 @@ jobs: profile: minimal override: false - # - name: install virtualenv - # run: pip install virtualenv - # - # - name: install dependencies - # run: make env - # # - name: build docker image - # run: make docker-build - # - #- name: start docker container - # run: make docker-run + - name: install virtualenv + run: pip install virtualenv - #- name: run tests - # run: make test + - name: install dependencies + run: make env - #- name: stop docker container - # run: make docker-stop + - name: build docker image + run: make docker-build + + - name: start docker container + run: make docker-run + + - name: run tests + run: make test + + - name: stop docker container + run: make docker-stop - name: Login to DockerHub if: (github.ref == 'refs/heads/master' || github.event_name == 'push') && github.repository == 'mCaptcha/cache' diff --git a/Dockerfile b/Dockerfile index 3f6fee0..e3cc27d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,15 +13,13 @@ RUN set -ex; \ DEBIAN_FRONTEND=noninteractive \ apt-get install -y --no-install-recommends redis clang gcc COPY Cargo.toml Cargo.lock /src/ -RUN mkdir -p /src/src && touch /src/src/lib.rs -RUN cargo build --release -COPY . . +COPY src/lib.rs /src/src/lib.rs +RUN cargo build --release || true +COPY . /src/ +RUN ls /src/src RUN cargo build --release - -#FROM redisfab/redis:${REDIS_VER}-${ARCH}-${OSNICK} FROM redis:${REDIS_VER}-${OSNICK} - ARG REDIS_VER ENV LIBDIR /usr/lib/redis/modules @@ -29,6 +27,5 @@ WORKDIR /data RUN mkdir -p "$LIBDIR" COPY --from=builder /src/target/release/libcache.so "$LIBDIR" - EXPOSE 6379 CMD ["redis-server", "--loadmodule", "/usr/lib/redis/modules/libcache.so"] diff --git a/Makefile b/Makefile index b7a57fc..a4e2cc2 100644 --- a/Makefile +++ b/Makefile @@ -19,16 +19,14 @@ doc: cargo doc --no-deps --workspace --all-features --document-private-items docker: - docker build -t mcaptcha/cache:broken-build . - #docker build -t mcaptcha/cache:0.1.0-beta -t mcaptcha/cache:latest . - #docker push mcaptcha/cache:0.1.0-beta - docker push mcaptcha/cache:broken-build + docker build -t mcaptcha/cache:0.1.0-beta -t mcaptcha/cache:latest . + docker push mcaptcha/cache:0.1.0-beta docker-build: docker build -t mcaptcha/cache:0.1.0-beta -t mcaptcha/cache:latest . docker-run: - docker run --name=$(DOCKER_CONTAINER) \ + docker run -d --name=$(DOCKER_CONTAINER) \ --publish 6379:6379 \ mcaptcha/cache:latest