Skip to content

Commit

Permalink
build: build all from one makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
vitonsky committed Jun 3, 2024
1 parent 418e9ed commit db5fb75
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 40 deletions.
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:14
WORKDIR /usr/src/app
WORKDIR /mnt/builder

RUN apt-get update

Expand All @@ -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
Expand Down
28 changes: 8 additions & 20 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SHELL=/bin/bash
DOCKER_COMPOSE=docker-compose

build: prepare
npm run build:all
Expand 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
npm run build:firefox
7 changes: 4 additions & 3 deletions thirdparty/bergamot/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:14
WORKDIR /usr/src/app
WORKDIR /mnt/bergamot

# Install system deps
RUN apt-get update
Expand All @@ -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
RUN npm install
18 changes: 2 additions & 16 deletions thirdparty/bergamot/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

0 comments on commit db5fb75

Please sign in to comment.