Skip to content

Commit

Permalink
chore(garden-service): get rid of ts-node in testing and building pro…
Browse files Browse the repository at this point in the history
…cess

This notably excludes the gulpfiles themselves. I didn't see a reason to
move those to plain JS.

Some implications of the change:
1. I moved the garden bin file from `garden-service/static/bin` to
   `garden-service/bin`. You may need to update your own symlinks accordingly.
2. You now *have to* run builds before testing, or keep `npm run tsc` or
   `npm run dev` running for test code to be updated.
3. We need to be careful to use constants and not relative paths to code files
   in most cases, since data/static files aren't necessarily relative to code
   files in the same way pre and post build.
  • Loading branch information
edvald committed May 31, 2019
1 parent 7cf91f2 commit 344392c
Show file tree
Hide file tree
Showing 53 changed files with 205 additions and 246 deletions.
71 changes: 35 additions & 36 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,31 +134,11 @@ commands:
# Jobs section
#
jobs:
build-service-docker:
<<: *node-config
steps:
- checkout
# This is to copy the pre-build build output from test-service (this should be a different step)
- *attach-workspace
- include_dashboard
- docker_build:
context: garden-service
release-service-docker:
<<: *node-config
steps:
- checkout
# This is to copy the pre-build build output from test-service (this should be a different step)
- *attach-workspace
- docker_release:
context: garden-service
image: $DOCKER_ORG/garden
build-service:
<<: *node-config
steps:
- checkout
- run: sudo apt-get update && sudo apt-get install rsync
- setup_remote_docker:
docker_layer_caching: true
- npm_install
- run:
name: build
Expand Down Expand Up @@ -202,24 +182,10 @@ jobs:
npm test
environment:
CHOKIDAR_USEPOLLING: "1"
test-dashboard:
<<: *node-config
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- npm_install
- run:
name: Test dashboard
command: |
cd dashboard
npm test
build-dashboard:
<<: *node-config
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- npm_install
- run:
name: Build dashboard
Expand All @@ -235,6 +201,35 @@ jobs:
paths:
# Save the built output for future
- dashboard/build/
test-dashboard:
<<: *node-config
steps:
- checkout
- npm_install
- *attach-workspace
- run:
name: Test dashboard
command: |
cd dashboard
npm test
build-service-docker:
<<: *node-config
steps:
- checkout
# This is to copy the pre-build build output from test-service (this should be a different step)
- *attach-workspace
- include_dashboard
- docker_build:
context: garden-service
release-service-docker:
<<: *node-config
steps:
- checkout
# This is to copy the pre-build build output from test-service (this should be a different step)
- *attach-workspace
- docker_release:
context: garden-service
image: $DOCKER_ORG/garden
release-service-pkg:
<<: *node-config
steps:
Expand All @@ -255,9 +250,13 @@ workflows:
commit:
jobs:
- build-service
- test-service
- test-service:
requires:
- build-service
- build-dashboard
- test-dashboard
- test-dashboard:
requires:
- build-dashboard
master:
jobs:
# Duplicated here so we can reference steps that depends on it
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ Our release process generates the following packages:
### Process

The release process is twofold, first a [release script](https://github.com/garden-io/garden/blob/master/bin/release.ts) is run. The script has the signature: `./bin/release.tsx <minor | patch | preminor | prepatch | prerelease> [--force]` and does the following:

* Checks out a branch named `release-<version>`.
* Updates `package.json` and `package-lock.json` for `garden-service` and the changelog.
* Commits the changes, tags the commit and pushes the tag and branch, triggering a CI process the creates the release artifacts.
Expand All @@ -195,7 +196,7 @@ Second, we manually upload the artifacts generated in CI to our Github releases
To make a new release, set your current working directory to the garden root directory and follow the steps below.

1. The first step depends on the release type:
* If you're making the first pre-release, run `./bin/release.tsx prerelease` from `master`.
* If you're making the first pre-release, run `./bin/release.ts prerelease` from `master`.
* If you’ve already created a prerelease, e.g. `v1.2.3-0`, and want to create a new prerelease `v1.2.3-1` which includes changes made on master since `v1.2.3-0` was created, do the following:
* `git checkout v1.2.3-0`
* `git rebase master`
Expand Down
2 changes: 1 addition & 1 deletion bin/garden
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

garden_root=$(cd `dirname $0` && cd $(git rev-parse --show-toplevel) && pwd)
node ${garden_root}/garden-service/static/bin/garden "$@"
node ${garden_root}/garden-service/bin/garden "$@"
2 changes: 1 addition & 1 deletion bin/garden-debug
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

garden_root=$(cd `dirname $0` && cd $(git rev-parse --show-toplevel) && pwd)
node --inspect ${garden_root}/garden-service/static/bin/garden "$@"
node --inspect ${garden_root}/garden-service/bin/garden "$@"
8 changes: 4 additions & 4 deletions bin/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import chalk from "chalk"
import parseArgs = require("minimist")
import replace = require("replace-in-file")
import deline = require("deline")
import { resolve, join } from "path"
import { resolve } from "path"
import { GARDEN_SERVICE_ROOT } from "../garden-service/src/constants"

type ReleaseType = "minor" | "patch" | "preminor" | "prepatch" | "prerelease"
const RELEASE_TYPES = ["minor", "patch", "preminor", "prepatch", "prerelease"]
Expand All @@ -30,8 +31,7 @@ async function release() {
const argv = parseArgs(process.argv.slice(2))
const releaseType = <ReleaseType>argv._[0]
const force = argv.force
const gardenRoot = resolve(__dirname, "..")
const gardenServiceRoot = join(gardenRoot, "garden-service")
const gardenRoot = resolve(GARDEN_SERVICE_ROOT, "..")

// Check if branch is clean
try {
Expand All @@ -47,7 +47,7 @@ async function release() {
// Bump package.json and package-lock.json version. Returns the version that was set.
const version = await execa.stdout("npm", [
"version", "--no-git-tag-version", releaseType,
], { cwd: gardenServiceRoot })
], { cwd: GARDEN_SERVICE_ROOT })

const branchName = `release-${version}`

Expand Down
1 change: 1 addition & 0 deletions garden-service/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ gulpfile.ts
tsconfig.*
**/.garden
**/node_modules
build/test
8 changes: 4 additions & 4 deletions garden-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ RUN apk add --no-cache \
rsync \
ca-certificates \
tar \
gzip \
&& curl -L -o /usr/local/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/v1.14.0/bin/linux/amd64/kubectl" \
&& chmod +x /usr/local/bin/kubectl
gzip

WORKDIR /garden

Expand All @@ -28,5 +26,7 @@ ADD static /garden/static

WORKDIR /project

RUN ln -s /garden/static/bin/garden /bin/garden \
RUN ln -s /garden/bin/garden /bin/garden \
&& chmod +x /bin/garden

ENTRYPOINT [/garden/bin/garden]
8 changes: 6 additions & 2 deletions garden-service/bin/build-pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ echo "-> Copying files to tmp build dir..."
mkdir -p dist
rm -rf tmp/dist
mkdir -p tmp/dist
mkdir tmp/dist/bin
mkdir tmp/dist/build

cp -r package.json build node_modules tmp/dist
cp -r package.json package-lock.json node_modules Dockerfile tmp/dist
cp -r build/src tmp/dist/build/src
cp bin/garden tmp/dist/bin
rsync -r --exclude=.garden --exclude=.git static tmp/dist

echo "-> Building executables..."
Expand Down Expand Up @@ -45,7 +49,7 @@ mkdir macos-amd64
mv garden-cli-macos macos-amd64/garden
cp -r ../tmp/dist/static macos-amd64
# need to include the .node binary for fsevents
cp ../lib/fsevents/node-v64-darwin-x64/fse.node macos-amd64
cp ../lib/fsevents/node-v64-darwin-x64/fse.node macos-amd64/fsevents.node
echo " -> tar"
tar -czf garden-${version}-macos-amd64.tar.gz macos-amd64

Expand Down
8 changes: 0 additions & 8 deletions garden-service/bin/exec

This file was deleted.

5 changes: 5 additions & 0 deletions garden-service/bin/garden
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

const cli = require("../build/src/cli/cli")

cli.run()
5 changes: 5 additions & 0 deletions garden-service/bin/garden-debug
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node --inspect

const cli = require("../build/src/cli/cli")

cli.run()
24 changes: 0 additions & 24 deletions garden-service/bin/generate-docs.ts

This file was deleted.

24 changes: 8 additions & 16 deletions garden-service/gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import {
spawn as _spawn,
} from "child_process"
import { resolve, join } from "path"
import { spawn } from "../support/support-util"

const pegjs = require("gulp-pegjs")
const sourcemaps = require("gulp-sourcemaps")
const ts = require("gulp-typescript")

const tsConfigFilename = "tsconfig.build.json"
const tsConfigFilename = "tsconfig.json"
const tsConfigPath = resolve(__dirname, tsConfigFilename)
const tsProject = ts.createProject(tsConfigPath, {
declaration: true,
Expand All @@ -25,19 +22,17 @@ const tsProject = ts.createProject(tsConfigPath, {
const pegjsSources = resolve(__dirname, "src", "*.pegjs")

const destDir = resolve(__dirname, "build")
const binDir = resolve(__dirname, "bin")
const binDir = resolve(destDir, "src", "bin")

module.exports = (gulp) => {
gulp.task("add-version-files", () => spawn(join(binDir, "add-version-files.ts"), []))
gulp.task("add-version-files", () => spawn("node", [join(binDir, "add-version-files.js")]))

gulp.task("build-container", () => spawn("docker", ["build", "-t", "gardendev/garden:latest", __dirname]))

gulp.task("generate-docs", () => spawn(join(binDir, "generate-docs.ts"), []))
gulp.task("generate-docs", () => spawn("node", [join(binDir, "generate-docs.js")]))

gulp.task("pegjs", () =>
gulp.src(pegjsSources)
.pipe(pegjs({ format: "commonjs" }))
.pipe(gulp.dest(destDir)),
.pipe(gulp.dest(join(destDir, "src"))),
)

gulp.task("pegjs-watch", () =>
Expand All @@ -52,12 +47,9 @@ module.exports = (gulp) => {
.pipe(gulp.dest(destDir)),
)

gulp.task("build", gulp.parallel(
"add-version-files", "generate-docs", "pegjs", "tsc",
))

gulp.task("build-ci", gulp.parallel(
"add-version-files", "generate-docs", "pegjs", "tsc",
gulp.task("build", gulp.series(
gulp.parallel("pegjs", "tsc"),
gulp.parallel("add-version-files", "generate-docs"),
))
}

Expand Down
31 changes: 0 additions & 31 deletions garden-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 344392c

Please sign in to comment.