From 97db774e70a0a1f661798442178a4890f72a42ca Mon Sep 17 00:00:00 2001 From: realaravinth Date: Thu, 15 Jul 2021 15:27:01 +0530 Subject: [PATCH] docker: wasm build step --- .dockerignore | 4 ++++ Dockerfile | 20 ++++++++++++++++---- Makefile | 17 +++++++++-------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.dockerignore b/.dockerignore index 9b56622c..b4f431c8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,3 +8,7 @@ node_modules/ ./templates/**/*.js /static/cache/bundle/* src/cache_buster_data.json + +browser/target +browser/cobertura.xml +browser/docs diff --git a/Dockerfile b/Dockerfile index b2f86b7b..32ef93ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,28 @@ -FROM node:14.16.0 as frontend +FROM rust:latest as wasm LABEL org.opencontainers.image.source https://github.com/mCaptcha/mCaptcha +RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh +COPY browser/ /browser +WORKDIR /browser +RUN wasm-pack build --release + +FROM node:14.16.0 as frontend +COPY package.json yarn.lock /src/ +COPY --from=wasm /browser /src/browser WORKDIR /src -COPY package.json yarn.lock ./ RUN yarn install -COPY . . +WORKDIR / +RUN mkdir -p /src/static/cache/bundle +COPY tsconfig.json webpack.config.js jest.config.ts /src/ +COPY templates /src/templates +WORKDIR /src RUN yarn build FROM rust:latest as rust -COPY --from=frontend /src /src WORKDIR /src +COPY . . +COPY --from=frontend /src/static/cache/bundle /src/static/cache/bundle RUN cargo build --release FROM debian:buster diff --git a/Makefile b/Makefile index b8f8e7e5..7266e8d1 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,12 @@ default: frontend cargo build clean: - cargo clean - rm -rf browser/pkg || true - rm ./src/cache_buster_data.json || true - rm -rf ./static/cache/bundle || true - rm -rf ./assets || true + @cargo clean + @yarn cache clean + @-rm -rf browser/pkg + @-rm ./src/cache_buster_data.json + @-rm -rf ./static/cache/bundle + @-rm -rf ./assets coverage: migrate cd browser && cargo tarpaulin -t 1200 --out Html @@ -21,10 +22,10 @@ doc: cargo doc --no-deps --workspace --all-features cd browser && cargo doc --no-deps --workspace --all-features -docker-build: +docker: docker build -t mcaptcha/mcaptcha:master -t mcaptcha/mcaptcha:latest . -docker-publish: docker-build +docker-publish: docker push mcaptcha/mcaptcha:master docker push mcaptcha/mcaptcha:latest @@ -61,7 +62,7 @@ help: @echo ' clean - drop builds and environments' @echo ' coverage - build test coverage in HTML format' @echo ' dev-env - download dependencies' - @echo ' docker-build - build docker image' + @echo ' docker - build docker image' @echo ' docker-publish - build and publish docker image' @echo ' doc - build documentation' @echo ' frontend - build static assets in prod mode'