Skip to content

Commit

Permalink
Dockerfile: Check yarn.lock only on CI servers (#1076)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravicious authored Aug 3, 2022
1 parent 7836db2 commit 7125001
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
8 changes: 8 additions & 0 deletions web/.cloudbuild/ci/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ steps:
id: install-deps
args:
- build
- '--build-arg'
- YARN_FROZEN_LOCKFILE=true
- .

- name: gcr.io/cloud-builders/docker
Expand All @@ -30,6 +32,8 @@ steps:
- build
- '--build-arg'
- NPM_SCRIPT=lint
- '--build-arg'
- YARN_FROZEN_LOCKFILE=true
- .

- name: gcr.io/cloud-builders/docker
Expand All @@ -39,6 +43,8 @@ steps:
- build
- '--build-arg'
- NPM_SCRIPT=build-teleport
- '--build-arg'
- YARN_FROZEN_LOCKFILE=true
- .

- name: gcr.io/cloud-builders/docker
Expand All @@ -48,4 +54,6 @@ steps:
- build
- '--build-arg'
- NPM_SCRIPT=build-and-package-term
- '--build-arg'
- YARN_FROZEN_LOCKFILE=true
- .
2 changes: 2 additions & 0 deletions web/.cloudbuild/ci/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ steps:
- build
- '--build-arg'
- NPM_SCRIPT=test
- '--build-arg'
- YARN_FROZEN_LOCKFILE=true
- .
15 changes: 6 additions & 9 deletions web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ COPY README.md packages/webapps.e/telepor[t]/package.json web-apps/packages/weba

# download and install npm dependencies
WORKDIR web-apps
# Install JavaScript dependencies and manually check if yarn.lock needs an update.
# Yarn v1 doesn't respect the --frozen-lockfile flag when using workspaces.
# https://github.com/yarnpkg/yarn/issues/4098
RUN cp yarn.lock yarn-before-install.lock \
&& yarn install \
&& git diff --no-index --exit-code yarn-before-install.lock yarn.lock || \
{ echo "yarn.lock needs an update. Run yarn install, verify that correct dependencies were installed \
and commit the updated version of yarn.lock. Make sure you have the packages/webapps.e submodule \
cloned first."; exit 1; }
ARG YARN_FROZEN_LOCKFILE
RUN if [ -n "$YARN_FROZEN_LOCKFILE" ]; then \
./packages/build/scripts/yarn-install-frozen-lockfile.sh; \
else \
yarn install; \
fi

# copy the rest of the files and run yarn build command
COPY . .
Expand Down
16 changes: 16 additions & 0 deletions web/packages/build/scripts/yarn-install-frozen-lockfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -ex

# Install JavaScript dependencies and manually check if yarn.lock needs an update.
# Yarn v1 doesn't respect the --frozen-lockfile flag when using workspaces.
# https://github.com/yarnpkg/yarn/issues/4098

message="yarn.lock needs an update. Run yarn install, verify that correct dependencies were \
installed and commit the updated version of yarn.lock. Make sure you have the packages/webapps.e \
submodule initialized and updated first."

cp yarn.lock yarn-before-install.lock
yarn install
git diff --no-index --exit-code yarn-before-install.lock yarn.lock ||
{ echo "$message" ; exit 1; }

0 comments on commit 7125001

Please sign in to comment.