| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This repo implements the Garlic Tech development infrastructure. The infrastructure is mainly based on Docker containers, because:
Before being able to use the workflows, you have to
If you use a private docker registry (in case of developing a dockerized server or using them):
These steps describe the development flow generally. We describe the individual differences/details in the docs of the specialized workflows. A generally valid summary:
Generally, you can develop in Javascript, Coffeescript, Typescript: the build system supports all these files, you can even mix them. At the end, you get a pure javascript production build.
Actually, the above development steps are for "deployable" repos: individual websites, servers, etc. When we really want to share code, we extract common code to individual repos. Those repos are normally not "deployable" ones, only the deployable projects use them. Now, developing the shared repos with the above method is really cumbersome: each changes should go through a Travis build and publishing process, it is quite slow.
Now, for the shared code, we utilize the excellent git subrepo project. Go to the web site and install the tool. So, as for subrepos:
How to add a subrepo. We do it by an example: add the authentication-lib repo as a subrepo. Check the library code: it has no docker and other codes, it has no projct/src folder, etc.
git subrepo clone https://github.com/garlictech/authentication-lib.git -b subrepo project/subrepos/\@garlictech/authentication-lib
Tha above command adds the HEAD of the subrepos branch of the auth. lib repo under project/subrepos folder. Using the project/subrepos folder is mandatory, as the workflows expect this folder structure.
Then, add the following to the dependencies section of the package.json:
"@garlictech/authentication-lib": "file:./project/subrepos/@garlictech/authentication-lib"
So, you can:
The cool thing is that the subrepos are mounted into the development docker containers, so you achieved a kind of (but more effective) npm link that works in the container as well.
Now, the dockerized environment requires some extras:
COPY project/subrepos /app/project/subrepos/ RUN scripts/install_dependencies.js
This is because you have to install the subrepo dependencies inside the containers as well, so you need to inject the subrepo package.json-s as well. This is the simplest way. When you start the development container with docker-compose, it will override the /app/project/subrepos/ folder with the mounted external code, so all the host changes in the subrepos will trigger a rebuild (in watch mode).
Well, this has some minor inconveniences, compered to the "undockerized" development: whatever dependencies you install, you have to inject them into the development container as well. Follow these steps:
Mind, that when you execute npm run setup, the command will update the dependencies to the ones that the docker dev container supports!
Only the following keys are merged: dependencies, peerDependencies, devDependencies.
At the end of each test run, you will receive a test coverage report. The tests fail if the coverage is below the threshold. The current values (they may increase in the future versions of the workflows):
You can access the coverage report in your project folder, under reports/coverage (open it in a browser). The system will create this folder after the very first test run.
You can execute a hook file before starting the tests, if you want to define globals, etc. The hook file must be in docker/unittest/index.js. The system will simply require this file before requiring any of the spec files.
// Display the original files in the stack traces
require('source-map-support').install()
// The coverage report covers only files that are included by any of the tests.
// This file tries to import as many files as possible, until at least one test covers them.
var requireDir = require('require-dir');
requireDir('../provider-lib/', {recurse: true})
requireDir('../deepstream-rxjs/', {recurse: true})
Similarly to the unit tests, you can execute a hook file before starting the tests if you want to define globals, etc. The hook file must be in docker/systemtest/index.js. The system simply require-s this file before requiring any of the spec files.
Depending on the workflow, we support typedoc and/or, in case of angular projects, compodoc. To access compodoc features, your project package.json should contain the following snipet in the scriptssection:
"doc:build": "docker/npm.sh doc:build", "doc:serve": "docker/npm.sh doc:serve", "doc:buildandserve": "docker/npm.sh doc:buildandserve"
The meaning and functionality are from the compodoc tutorial.
Your docker/npm.sh script should look like this:
#!/usr/bin/env bash
DOCKER_COMPOSE="docker-compose -f docker/docker-compose.webpack.yml"
if [[ $DEBUG ]]; then
DOCKER_COMPOSE="${DOCKER_COMPOSE} -f docker/docker-compose.debug.yml"
fi
${DOCKER_COMPOSE} run -p 8092:8092 gtrack-admin-site.webpack-server npm run $@
The main point is the port mapping here: the built-in compodoc server runs at port 8092, map it as you wish.
The following command starts the system in debug mode:
make systemtest-run-debug
The execution stops at the beginning, and itt waits for debugger connection. The debugger runs on port 9229, but you can map it to a different port, in the appropriate docker compose file (normally, the one including systemtest in its file name).
If you use vscode, use the following config in your launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Launch Program",
"protocol": "inspector",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"localRoot": "${workspaceFolder}/dist",
"remoteRoot": "/app/dist",
"address": "localhost",
"port": 9229
}
]
}
The folder contains some scripts and Docker compose files: they compose the Docker based development infrastructure. You can finetune them. The most important file is the docker-compose.dependencies.yml file: add all the external docker services that you need during the development, etc.
For CI/CD, we use Travis. You can find enevrything in the .travis.yml file. Keep that file as clean as possible, and use hook scripts instead, implementing a lifecycle functionality. All the hooks are in the hooks/travis folder.
See the rest of the scripts at the individual project descriptions.
Clean the dist folder and the build artifacts.
Execute the linter. Is also fixes some fixable errors in-place (mutates the files).
Using the Prettier project, it fixes some spacing/comma errors (replaces tabs with 2 spaces, etc.).
Commit the git changes. It will use commitizen, to create proper commit comments. You should not use git commit directly!
The command requires that user.name and user.email be configured, othwerwise it will complain about the missing GH_USER or GH_EMAIL environmant variables. Do it like
git config --global user.name "myname" git config --global user.email "email@example.com"
Basically, for internal usage: executes npm commands inside the development container.
Used by Travis CI only.
Releses the project: tags the sources in Github, creates CHANGELOG, and publishes the project to the npm repository. Actually, you should not use it directly: Travis should release a project exclusively.
Log in to the container and see its actual content:
npm run bash
The command opens a bash session where you can directly change the development container. Mind, that those changes are not persistent, you loose them when you exit.
We control the deployment with Travis. So, the deployment instuctions must be implemented in the Travis hooks, in the hooks/travis folder. The deployment may be:
BELOW THIS IS THE OLD DOCMENTATION, BEING REWRITTEN!
So, build the image
npm run build:dev
Then, update your local files. This step ensures that your lint, tsconfig, etc. files conform the latest requirement, and updates the general dependencies in your package.json file.
npm run setup
After this step, you have a .env file, with some basic settings. Like NODE_ENV...
Default: development.
The (private) docker registry of the project.
The project slug. Basically, it is the repo part of the github slug.
The Docker image of the service. Basically, it is the repo part of the github slug.
Your organization. The organization part of the github slug.
Each project type (web site, angular module, etc.) has its own individual workflow implementation. Follow the links to learn about them:
tl;dr
npm run setup-dev make build make start make unittest make systemtest make smoketest git add . npm run commit
As you can see, in server side, we use Make, because it provides extreme flexibility. For the individual commands, read the makefile comments inside the file, they should be obvious.
Builds the development service image(s). Uses Dockerile.dev. The image is derived from workflows-server, pulled from your organization docker registry.
Start the development service. It uses docker/docker-compose.yml.
Execute the unit tests once.
Execute the system tests.
We use commitizen ti create commit comments. It is important to use it, because, in Travis side, releases are created by parsing the commit comments. If the system cannot detect that it is a change with functional improvments, then it will not publish a new release, so the changes will not be integrated automatically into the end product. More info:
TBD
TBD
When you set the DEBUG environment variable to true, then all the processes (server, test, etc.) will stop at the beginning of the execution, and will wait for a debugger. Attach the debugger and continue.
A good debugger is built in the free Visual Studio Code tool.
tl;dr
npm run build:dev npm run setup npm start npm run unittest git add . npm run commit
The process assumes that you either:
The main and generic development procedures are implemented in npm scripts. You can get a list of them by running
npm run
Call a script like this:
npm run <script name> -- [OPTIONS]
Some of the scripts can accept optional parameters, add then after the double hyphens.
The scripts start the appropriate docker containers implementing the required operation and containing the required, pre-installed, configured software required by the operation. This approach is much superior to the local installation approach: you do not have to install all the development packages for each components.
In the dockerfolder, you can find the basic, generated docker files and scripts. In most cases, they should be enough, but you can freely modify them, to implement some more complicated scenarios.
Builds the application-specific development Docker image. You have to build it whenever:
The build combines some docker_compose files in the docker folder of the project (they are also generated).
You can pass docker_compose build parameters to the process like:
npm run build -- --no-cache
This script can be invoked without 'run':
npm start
It launches the webpack development server and stars watching files. You can access your site in http://localhost:8081. If you change something in src, then it reloads the files in the browser.
Execute the unit tests:
npm run unittest
Execute the unit tests in watch mode:
npm run unittest:watch
npm run stop:dev
Stops the webpack dev server. Locally, you can do it with Ctrl-C, it is relevant in CI environments, for example, to stop the server programmatically.
npm run bash
Use bash inside the app container. It is good to inspect what is going on internally. It launches the webpack container containing your app and gives you a bash shell.
Executes the protractor bases e2e tests. It uses a different container, based on garlictech-protractor. What it does:
The protractor is pre-configured inside the container.
The tests start an individual webpack-dev-server with the project to be tested, and they start the required dependencies. You can use the following options as well:
npm run e2etest stop
The above command equals to docker_compose <all service files> down, and stops all services required by the e2e test.
npm run e2etest bash
Starts an e2e test container with a bash session.
npm run e2etest -- <parameters>
Pass the parameters to the e2e test service.
It is quite difficult to figure out why your tests failed without seeing them in the browser. So, the protractor workflow image provides you a VNC session with a running Chrome browser, attached to the test. Start the test like this:
npm run e2etest -- --elementExplorer
The test starts, and stops immediately, waiting for a vnc session. Download a VNC client, start it, and attach
npm run commit
We use semantic release and commitizen to commit our code to the repos. Travis then determines the version numbering and publishes a new version to npm.
The garlictech generators prepare your project to use these features automatically. The required software and the workflow implementation are in the workflows-common docker image.
Actually, we follow the open source sw development guidelines, adapted to private environments. We suggest this egghead tutorial.
You have to modify this folder only if your project is a module (in package.json: garlic.type property is "module"). Otherwise, simply delete this folder. Actually, this is a full web site to visualize and test your component.=
See here.
| Back | FazBrowse Home | New Git URL |