Skip to content
Permalink
Browse files
allow skipping frontend build in Docker
That option allows having backend-only build,
skipping the long frontend build and test step.
Frontend developers run NodeJS locally and usually
don't need to have frontend built inside the docker image.
  • Loading branch information
Dmitry Verkhoturov authored and Umputun committed Feb 16, 2022
1 parent 214e183 commit f448208475a7675dfb89fb8b3bd9022cbf9d41d3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
@@ -23,7 +23,9 @@ RUN \
CGO_ENABLED=1 go test -race -p 1 -timeout="${BACKEND_TEST_TIMEOUT:-300s}" -covermode=atomic -coverprofile=/profile.cov_tmp ./... && \
cat /profile.cov_tmp | grep -v "_mock.go" > /profile.cov ; \
golangci-lint run --config ../.golangci.yml ./... ; \
else echo "skip backend tests and linter" ; fi
else \
echo "skip backend tests and linter" \
; fi

RUN \
version="$(/script/version.sh)" && \
@@ -33,25 +35,41 @@ RUN \
FROM --platform=$BUILDPLATFORM node:16.13.2-alpine as build-frontend-deps

ARG CI
ARG SKIP_FRONTEND_BUILD
ENV HUSKY_SKIP_INSTALL=true

RUN apk add --no-cache --update git
RUN if [ -z "$SKIP_FRONTEND_BUILD" ] ; then \
apk add --no-cache --update git \
; fi
ADD frontend/package.json /srv/frontend/package.json
ADD frontend/package-lock.json /srv/frontend/package-lock.json
RUN cd /srv/frontend && CI=true npm ci --loglevel warn
WORKDIR /srv/frontend
RUN mkdir node_modules
RUN if [ -z "$SKIP_FRONTEND_BUILD" ] ; then \
CI=true npm ci --loglevel warn \
else \
echo "skip frontend build" \
; fi

FROM --platform=$BUILDPLATFORM node:16.13.2-alpine as build-frontend

ARG CI
ARG SKIP_FRONTEND_TEST
ARG SKIP_FRONTEND_BUILD
ARG NODE_ENV=production

COPY --from=build-frontend-deps /srv/frontend/node_modules /srv/frontend/node_modules
ADD frontend /srv/frontend
RUN cd /srv/frontend && \
if [ -z "$SKIP_FRONTEND_TEST" ] ; then npm run lint test check; \
else echo "skip frontend tests and lint" ; npm run build ; fi && \
rm -rf ./node_modules
WORKDIR /srv/frontend
RUN mkdir public
RUN if [ -z "$SKIP_FRONTEND_BUILD" ] ; then \
if [ -z "$SKIP_FRONTEND_TEST" ] ; then \
npm run lint test check; \
else \
echo "skip frontend tests and lint" ; npm run build \
; fi \
; fi
RUN rm -rf ./node_modules

FROM umputun/baseimage:app-v1.8.0

@@ -13,6 +13,7 @@ services:
dockerfile: Dockerfile
args:
- SKIP_BACKEND_TEST=true
- SKIP_FRONTEND_BUILD=true
# - NODE_ENV=development

image: umputun/remark42:dev
@@ -11,10 +11,7 @@ cp compose-dev-backend.yml compose-private.yml
# now, edit / debug `compose-private.yml` to your heart's content
# build and run
make rundev
# this is an equivalent of these two commands:
# docker-compose -f compose-private.yml build
# docker-compose -f compose-private.yml up
docker-compose -f compose-private.yml up --build
```

It starts Remark42 on `127.0.0.1:8080` and adds local OAuth2 provider "Dev". To access the UI demo page go to <http://127.0.0.1:8080/web/>. By default, you would be logged in as `dev_user`, defined as admin. You can tweak any of the [supported parameters](https://remark42.com/docs/configuration/parameters/) in corresponded yml file.
@@ -41,10 +41,7 @@ cp compose-dev-frontend.yml compose-private.yml
# now, edit / debug `compose-private.yml` to your heart's content
# build and run
make rundev
# this is an equivalent of these two commands:
# docker-compose -f compose-private.yml build
# docker-compose -f compose-private.yml up
docker-compose -f compose-private.yml up --build
```

Then in the new terminal tab or window, run the following to start the frontend with Hot Reloading:
@@ -60,7 +57,7 @@ It starts Remark42 backend on `127.0.0.1:8080` and adds local OAuth2 provider "D

Frontend Docker Compose config (`compose-dev-frontend.yml`) by default skips running backend related tests and sets `NODE_ENV=development` for frontend build.

**Important**: Before submitting your changes as a Pull Request, re-run the backend using the `make rundev` command and test your changes against <http://127.0.0.1:8080/web/>, frontend, built statically (unlike frontend on port 9000, which runs dynamically). That is how Remark42 authors will test your changes once you submit them.
**Important**: Before submitting your changes as a Pull Request, run the backend using the `docker-compose -f compose-dev-frontend.yml build --build-arg SKIP_FRONTEND_BUILD=""; docker-compose -f compose-private.yml up` command and test your changes against <http://127.0.0.1:8080/web/>, frontend, built statically (unlike frontend on port 9000, which runs dynamically). That is how Remark42 authors will test your changes once you submit them.

#### Static build

0 comments on commit f448208

Please sign in to comment.