Commit e9cd32b9 authored by Saul Shanabrook's avatar Saul Shanabrook

Run everything in Docker in CI

parent efe692b3
......@@ -32,6 +32,7 @@
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts",
"docker": "environments/environment.docker.ts",
"extension": "environments/environment.extension.ts"
}
}
......
node_modules
image
documentation
.git
\ No newline at end of file
......@@ -97,3 +97,5 @@ web-ext-artifacts
archive.zip
documentation/
image
image: node:6.10
image: registry.gitlab.com/passit/docker-compose
services:
- docker:dind
variables:
IMAGE_NAME: registry.gitlab.com/passit/passit-frontend
DOCKER_DRIVER: overlay
DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
IS_TEST_MODE: 'True'
stages:
- install
- build
- test
- build_docker
- deploy
- pages
yarn_install:
stage: install
before_script:
- docker image load -i image
build:
stage: build
before_script:
- echo
script:
- yarn
- docker-compose build app
- docker save passitfrontend_app > image
artifacts:
paths:
- node_modules
- image
lint:
stage: test
dependencies:
- yarn_install
- build
script:
- yarn run lint
- docker-compose run --no-deps app lint
lint-ext:
stage: test
dependencies:
- yarn_install
- build
script:
- yarn run build:ext
- yarn run lint:ext
- yarn run build:ext:package
- docker-compose run --no-deps -v web-ext-artifacts:$PWD/web-ext-artifacts app ext
artifacts:
paths:
- web-ext-artifacts
......@@ -41,63 +46,54 @@ lint-ext:
test:
stage: test
dependencies:
- yarn_install
- build
script:
- yarn test -- --single-run
- docker-compose up -d selenium
- docker-compose run --no-deps app test:docker -- --single-run --progress false
e2e:
stage: test
services:
- postgres:9.6
- name: registry.gitlab.com/passit/passit-backend:master
alias: passit-backend
command: ["./manage.py", "runserver", "0.0.0.0:8000"]
dependencies:
- yarn_install
- build
script:
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - &&
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list &&
apt-get update &&
apt-get install -y google-chrome-stable xvfb &&
rm -rf /var/lib/apt/lists/*
- yarn run cie2e
- docker-compose up -d app selenium
- sleep 20
- docker-compose run app e2e:docker
build_yarn:
build_prod:
stage: test
script:
- yarn build -- --prod
dependencies:
- yarn_install
- build
script:
- docker build -f Dockerfile.prod -t ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME} .
- docker image save ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME} -o prod-image
artifacts:
paths:
- dist
- prod-image
build_docker:
stage: build_docker
image: docker:latest
services:
- docker:dind
push-images:
stage: deploy
dependencies:
- build_yarn
- build_prod
only:
- master
- dev
before_script:
- docker image load -i prod-image
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- docker pull ${IMAGE_NAME}:${CI_COMMIT_REF_NAME}
- docker build -f Dockerfile.prod -t ${IMAGE_NAME}:${CI_COMMIT_REF_NAME} .
- docker push ${IMAGE_NAME}:${CI_COMMIT_REF_NAME}
- docker push ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}
# from https://docs.openshift.com/online/dev_guide/managing_images.html#accessing-the-internal-registry
- docker login -u ${OPENSHIFT_USER} -p ${OPENSHIFT_KEY} https://registry.starter-us-east-1.openshift.com
- docker tag ${IMAGE_NAME}:${CI_COMMIT_REF_NAME} registry.starter-us-east-1.openshift.com/passit-staging/passit-frontend:master
- docker tag ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME} registry.starter-us-east-1.openshift.com/passit-staging/passit-frontend:master
- docker push registry.starter-us-east-1.openshift.com/passit-staging/passit-frontend:master
pages:
stage: pages
dependencies:
- yarn_install
- build
script:
- yarn run compodoc-gitlab
- docker-compose run --no-deps -v public:$PWD/public app compodoc-gitlab
artifacts:
paths:
- public
......
FROM node:6
FROM node:6-alpine
RUN mkdir /dist
WORKDIR /dist
# Yarn
RUN apt-get update && \
apt-get install apt-transport-https && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && \
apt-get install yarn
COPY package.json /dist/package.json
COPY yarn.lock /dist/yarn.lock
RUN yarn
RUN yarn install --frozen-lockfile && yarn cache clean
VOLUME /dist/node_modules
ENV PATH /dist/node_modules/.bin:$PATH
COPY . /dist/
ENTRYPOINT ["yarn", "run"]
\ No newline at end of file
FROM registry.gitlab.com/burke-software/passit-backend:master
ADD ./dist /code/dist
FROM passitfrontend_app
RUN yarn run build -- --prod --progress false
FROM registry.gitlab.com/passit/passit-backend:master
COPY --from=0 /dist/dist /code/dist
RUN ./manage.py collectstatic --noinput
......@@ -14,7 +14,7 @@ Please consider supporting developoment on [gratipay](https://gratipay.com/passi
This project uses docker compose.
1. Install docker and docker-compose
2. Run `docker-compose up`
2. Run `docker-compose up app`
The front end is now running on localhost:4200 and the backend docker image is running on localhost:8000
......@@ -25,19 +25,19 @@ sudo echo "fs.inotify.max_user_watches=524288" >> /etc/sysctl.conf
sudo sysctl fs.inotify.max_user_watches=524288
```
Run any one off commands like `docker-compose run --rm app bash` to execute them inside the docker container.
Run any one off commands like `docker-compose run --rm app lint` to execute them inside the docker container as yarn commands.
You may want to run the client without docker, just use angular cli.
### Rebuilding when changing package.json
If you need to run `npm install` you'll want to instead run `docker-compose build` and `docker-compose rm -v app` to remove the old container.
If you need to run `yarn install` you'll want to instead run `docker-compose build` and `docker-compose rm -v app` to remove the old container.
This is because node_modules are kept in a docker volume.
This is not ideal - if you know how to build node_modules into the container itself instead of a volume please let us know.
## Running unit tests
Run `npm test` to execute the unit tests via [Karma](https://karma-runner.github.io).
Run `yarn test` to execute the unit tests via [Karma](https://karma-runner.github.io).
Unit tests run in PhantomJS without a browser. This works because Crypto functions should always be mocked.
Crypto related tests should always be part of passit-sdk-js
......@@ -48,19 +48,19 @@ End-to-end tests are run via [Protractor](http://www.protractortest.org/).
We'll run the backend in docker and the frontend without for simplicity. Ensure you run `yarn` first to install local node modules.
1. Start backend `docker-compose -f docker-compose.e2e.yml -f docker-compose.yml up api`
1. Start backend `docker-compose up api`
2. Start dev server `yarn start`
3. Run test `yarn run e2e`
The e2e script will use the existing dev server (so you don't have to wait for it to rebuild each time)
In CI we run tests in docker. See .gitlab-ci.yml
In CI we run tests in docker. To do that run `docker-compose up -d app selenium; docker-compose run app e2e:docker`
## To Lint
```
$ npm run lint
$ yarn lint
```
# Development for web extension
......
version: '2'
services:
api:
environment:
DATABASE_URL: postgres://postgres:postgres@db:5432/postgres
IS_TEST_MODE: 'True'
......@@ -4,21 +4,27 @@ services:
build: .
volumes:
- .:/dist
command: npm start
command: start -- --environment=docker --disable-host-check
ports:
- "4200:4200"
- "4201:4201"
depends_on:
- api
api:
image: registry.gitlab.com/burke-software/passit-backend:latest
entrypoint: ./wait-for-db.sh
command: bash -c "./manage.py migrate --noinput; ./manage.py runserver 0.0.0.0:8000"
image: registry.gitlab.com/passit/passit-backend:latest
command: sh -c "./wait-for db:5432 -- ./manage.py migrate --noinput && ./manage.py runserver 0.0.0.0:8000"
environment:
DATABASE_URL: postgres://postgres:postgres@db:5432/postgres
IS_TEST_MODE: 'True'
ports:
- "8000:8000"
depends_on:
- db
db:
image: postgres:9.6
selenium:
image: selenium/standalone-chrome-debug:3.4.0
ports:
- "5900:5900"
volumes:
- /dev/shm:/dev/shm
......@@ -11,11 +11,22 @@ module.exports = function (config) {
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require( 'karma-phantomjs-launcher' ),
require( 'karma-webdriver-launcher' ),
require('@angular/cli/plugins/karma')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
customLaunchers: {
'selenium': {
base: 'WebDriver',
config: {
hostname: 'selenium'
},
browserName: 'chrome',
}
},
hostname: process.env.DOCKER ? process.env.HOSTNAME : undefined,
files: [
{ pattern: './src/test.ts', watched: false }
],
......
......@@ -9,10 +9,12 @@
"build:ext": "ng build --aot=true --env=extension",
"build:ext:package": "web-ext -s dist/ build --ignore-files assets/icon/manifest.json",
"test": "ng test",
"test:docker": "env DOCKER=true ng test --browser selenium",
"lint": "ng lint",
"lint:ext": "web-ext -s dist/ lint",
"ext": "yarn run build:ext -- --progress false && yarn run lint:ext && yarn run build:ext:package",
"e2e": "ng e2e -s false",
"cie2e": "export DISPLAY=:99.0; ./xvfb.sh start; sleep 2; yarn run webdriver-manager -- update --standalone false --gecko false; ng e2e --webdriver-update false",
"e2e:docker": "ng e2e -s false --config protractor.conf.docker.js",
"compodoc": "./node_modules/.bin/compodoc -p tsconfig.json",
"compodoc-serve": "./node_modules/.bin/compodoc -p tsconfig.json -s",
"compodoc-gitlab": "./node_modules/.bin/compodoc -p tsconfig.json -d public/"
......@@ -75,6 +77,7 @@
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "~0.2.2",
"karma-phantomjs-launcher": "~1.0.4",
"karma-webdriver-launcher": "^1.0.5",
"protractor": "~5.1.0",
"ts-node": "~3.1.0",
"tslint": "~5.4.0",
......
const { config } = require('./protractor.conf');
config.baseUrl = 'http://app:4200/'
config.directConnect = false
config.seleniumAddress = 'http://selenium:4444/wd/hub/'
exports.config = config
......@@ -24,7 +24,7 @@ exports.config = {
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
defaultTimeoutInterval: 60000,
print: function() {}
},
useAllAngular2AppRoots: true,
......
import { environment } from "../environments/environment";
const USE_SAME_DOMAIN = true;
export let API_URL: string;
if (environment.hasOwnProperty("api_url")) {
API_URL = environment["api_url"];
......@@ -23,4 +22,9 @@ if (environment.hasOwnProperty("api_url")) {
}
}
// if acccessing via e2e tests in docker
if (environment.docker && window.location.hostname === "app") {
API_URL = "http://api:8000/api/";
}
export const IS_EXTENSION = environment.extension;
export const environment = {
production: true,
extension: true,
docker: true
};
export const environment = {
production: true,
extension: true
extension: true,
docker: false
};
export const environment = {
production: true,
extension: false
extension: false,
docker: false
};
......@@ -5,5 +5,6 @@
export const environment = {
production: false,
extension: false
extension: false,
docker: false
};
......@@ -440,7 +440,7 @@ archiver-utils@^1.3.0:
normalize-path "^2.0.0"
readable-stream "^2.0.0"
archiver@~1.3.0:
archiver@1.3.0, archiver@~1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/archiver/-/archiver-1.3.0.tgz#4f2194d6d8f99df3f531e6881f14f15d55faaf22"
dependencies:
......@@ -569,6 +569,12 @@ async-foreach@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/async-foreach/-/async-foreach-0.1.3.tgz#36121f845c0578172de419a97dbeb1d16ec34542"
async@2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/async/-/async-2.0.1.tgz#b709cc0280a9c36f09f4536be823c838a9049e25"
dependencies:
lodash "^4.8.0"
async@^0.9.0:
version "0.9.2"
resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d"
......@@ -3849,6 +3855,12 @@ karma-source-map-support@^1.2.0:
dependencies:
source-map-support "^0.4.1"
karma-webdriver-launcher@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/karma-webdriver-launcher/-/karma-webdriver-launcher-1.0.5.tgz#b1c3cb347f26e786039c15abf7f19a7791e8ddd7"
dependencies:
wd "^1.0.0"
karma@~1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/karma/-/karma-1.7.0.tgz#6f7a1a406446fa2e187ec95398698f4cee476269"
......@@ -4211,6 +4223,10 @@ lodash@3.10.1, lodash@^3.8.0:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
lodash@4.16.2:
version "4.16.2"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.16.2.tgz#3e626db827048a699281a8a125226326cfc0e652"
lodash@^4.0.0, lodash@^4.0.1, lodash@^4.11.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0, lodash@^4.5.0, lodash@^4.8.0, lodash@~4.17.2, lodash@~4.17.4:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
......@@ -6974,6 +6990,13 @@ ultron@1.0.x:
version "1.0.2"
resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.0.2.tgz#ace116ab557cd197386a4e88f4685378c8b2e4fa"
underscore.string@3.3.4:
version "3.3.4"
resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-3.3.4.tgz#2c2a3f9f83e64762fdc45e6ceac65142864213db"
dependencies:
sprintf-js "^1.0.3"
util-deprecate "^1.0.2"
uniq@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/uniq/-/uniq-1.0.1.tgz#b31c5ae8254844a3a8281541ce2b04b865a734ff"
......@@ -7078,7 +7101,7 @@ useragent@^2.1.12:
lru-cache "2.2.x"
tmp "0.0.x"
util-deprecate@~1.0.1:
util-deprecate@^1.0.2, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
......@@ -7121,6 +7144,10 @@ validate-npm-package-license@^3.0.1:
spdx-correct "~1.0.0"
spdx-expression-parse "~1.0.0"
vargs@0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/vargs/-/vargs-0.1.0.tgz#6b6184da6520cc3204ce1b407cac26d92609ebff"
vary@^1, vary@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.1.tgz#67535ebb694c1d52257457984665323f587e8d37"
......@@ -7200,6 +7227,19 @@ wcwidth@^1.0.0:
dependencies:
defaults "^1.0.3"
wd@^1.0.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/wd/-/wd-1.4.0.tgz#85958787abc32f048d4b3927b2ab3c5fc8c9c9fa"
dependencies:
archiver "1.3.0"
async "2.0.1"
lodash "4.16.2"
mkdirp "^0.5.1"
q "1.4.1"
request "2.79.0"
underscore.string "3.3.4"
vargs "0.1.0"
web-ext-types@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/web-ext-types/-/web-ext-types-0.3.1.tgz#77c483ade0781d79b8697351e832017dd94661a6"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment