From ff7eb78b76c19395bb66b38002946f97e892b593 Mon Sep 17 00:00:00 2001 From: Jamal Carvalho Date: Mon, 28 Dec 2020 17:25:10 -0500 Subject: [PATCH] devtools: update frontend development environment config - Updates docker config to obfuscate git directories. - Adds a devtools script to run npm commands. - Node modules are installed on the host machine to enable autocomplete and intellisense IDEs. Change-Id: I8d739afdaa5982a433505f510dc731aa147c5ab6 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/280598 Trust: Jamal Carvalho Run-TryBot: Jamal Carvalho Reviewed-by: Jonathan Amsterdam Reviewed-by: Julie Qiu --- devtools/config/Dockerfile.npm | 10 +++++----- devtools/config/docker-compose.yaml | 11 ++++++++--- devtools/npm.sh | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100755 devtools/npm.sh diff --git a/devtools/config/Dockerfile.npm b/devtools/config/Dockerfile.npm index 0beec25e..b7964032 100644 --- a/devtools/config/Dockerfile.npm +++ b/devtools/config/Dockerfile.npm @@ -1,9 +1,9 @@ +# Copyright 2020 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + FROM node:14.15.1 WORKDIR /pkgsite -COPY package.json package-lock.json ./ - -RUN npm ci - -ENTRYPOINT [ "npm", "run" ] +ENTRYPOINT [ "npm" ] diff --git a/devtools/config/docker-compose.yaml b/devtools/config/docker-compose.yaml index 6372fe4c..ce7ac5d2 100644 --- a/devtools/config/docker-compose.yaml +++ b/devtools/config/docker-compose.yaml @@ -1,3 +1,7 @@ +# Copyright 2020 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + version: '3' services: npm: @@ -6,8 +10,9 @@ services: dockerfile: devtools/config/Dockerfile.npm image: pkgsite_npm init: true - ports: - - '5000:5000' volumes: - ../..:/pkgsite - - /pkgsite/node_modules + # Mounts empty volumes in place of git directories so they can't + # be written to during npm package installs. + - /pkgsite/.git + - /pkgsite/private/.git diff --git a/devtools/npm.sh b/devtools/npm.sh new file mode 100755 index 00000000..9dda16a6 --- /dev/null +++ b/devtools/npm.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env -S bash -e + +# Copyright 2020 The Go Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +source devtools/lib.sh || { echo "Are you at repo root?"; exit 1; } + +# Run an npm command and capture the exit code. +runcmd docker-compose -f devtools/config/docker-compose.yaml run --rm npm $@ +code=$EXIT_CODE + +# Perform docker cleanup. +runcmd docker-compose -f devtools/config/docker-compose.yaml down --remove-orphans + +# Exit with the code from the npm command. +exit $code