From db5fb752edc4bd82438d3c27788e886aea509adc Mon Sep 17 00:00:00 2001 From: Robert Vitonsky Date: Mon, 3 Jun 2024 20:10:41 +0200 Subject: [PATCH] build: build all from one makefile --- docker-compose.yml | 27 +++++++++++++++++++++++++++ Dockerfile => docker/Dockerfile | 3 ++- makefile | 28 ++++++++-------------------- thirdparty/bergamot/Dockerfile | 7 ++++--- thirdparty/bergamot/makefile | 18 ++---------------- 5 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 docker-compose.yml rename Dockerfile => docker/Dockerfile (92%) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..26a2e74f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: "3" +services: + linguist: + user: node + build: + context: . + dockerfile: ./docker/Dockerfile + volumes: + - ./build:/mnt/builder/build + - ./thirdparty/bergamot/build:/mnt/builder/thirdparty/bergamot/build + cap_add: + - SYS_ADMIN + + bergamot: + user: node + build: + context: ./thirdparty/bergamot + volumes: + - ./thirdparty/bergamot/build:/mnt/bergamot/build + - bergamot-translator:/mnt/bergamot/bergamot-translator + cap_add: + - SYS_ADMIN + +volumes: + # Persistent cache for fast builds in dev environment + bergamot-translator: + driver: local \ No newline at end of file diff --git a/Dockerfile b/docker/Dockerfile similarity index 92% rename from Dockerfile rename to docker/Dockerfile index 5391fcd9..f554793b 100644 --- a/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ FROM node:14 -WORKDIR /usr/src/app +WORKDIR /mnt/builder RUN apt-get update @@ -14,6 +14,7 @@ RUN apt-get install -y sudo && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoe RUN usermod -aG sudo node COPY . . +RUN mkdir -p thirdparty/bergamot/build RUN chown -R node:node . USER node diff --git a/makefile b/makefile index 3df1afe5..f0dde978 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,5 @@ SHELL=/bin/bash +DOCKER_COMPOSE=docker-compose build: prepare npm run build:all @@ -13,26 +14,13 @@ prepare: # Main targets # buildAll: buildThirdparty - make dockerBuildContainer - make dockerRunContainer - + mkdir -p ./build + ${DOCKER_COMPOSE} run linguist make dockerBuild + buildThirdparty: - cd ./thirdparty/bergamot - make dockerBuildContainer - make dockerRunContainer - -# -# Docker -# -dockerBuildContainer: - docker build . -t v/linguist - -dockerRunContainer: - npm run clean - # set current user id, to allow access to shared files - # use `--cap-add=SYS_ADMIN` to allow run puppeteer - docker run -v `pwd`:/out --user node --cap-add=SYS_ADMIN v/linguist make dockerBuild + mkdir -p ./thirdparty/bergamot/build + ${DOCKER_COMPOSE} run bergamot make build +# TODO: replace one target to multiple dockerBuild: - make build - sudo cp -R ./build /out/build \ No newline at end of file + npm run build:firefox \ No newline at end of file diff --git a/thirdparty/bergamot/Dockerfile b/thirdparty/bergamot/Dockerfile index 0a1de0c3..c19e7981 100644 --- a/thirdparty/bergamot/Dockerfile +++ b/thirdparty/bergamot/Dockerfile @@ -1,5 +1,5 @@ FROM node:14 -WORKDIR /usr/src/app +WORKDIR /mnt/bergamot # Install system deps RUN apt-get update @@ -9,11 +9,12 @@ RUN apt-get install -y cmake RUN apt-get install -y sudo && echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers RUN usermod -aG sudo node +RUN mkdir -p bergamot-translator + COPY . . RUN chown -R node:node . USER node # Prepare container -RUN npm install -RUN make prepareWasm \ No newline at end of file +RUN npm install \ No newline at end of file diff --git a/thirdparty/bergamot/makefile b/thirdparty/bergamot/makefile index 704d4a49..1aadfaba 100644 --- a/thirdparty/bergamot/makefile +++ b/thirdparty/bergamot/makefile @@ -10,11 +10,11 @@ buildWorker: npm run worker:build exportWasm: - - mkdir build + mkdir -p build cp bergamot-translator/build-wasm/bergamot-translator-worker.{js,wasm} build/ buildWasm: prepareWasm - - cd bergamot-translator && mkdir build-wasm + cd bergamot-translator && mkdir -p build-wasm source bergamot-translator/emsdk/emsdk_env.sh && cd bergamot-translator/build-wasm && emcmake cmake -DCOMPILE_WASM=on -DWORMHOLE=off ../ && emmake make -j2 && bash ../wasm/patch-artifacts-import-gemm-module.sh prepareWasm: @@ -25,17 +25,3 @@ prepareWasm: clean: rm -rf ./build - -# -# Docker tasks to unify build process -# - -dockerBuildContainer: - docker build . -t v/bergamot - -dockerRunContainer: clean - docker run -v `pwd`:/out --user node v/bergamot make dockerBuild - -dockerBuild: - make build - sudo cp -R ./build /out/build