Skip to content

Commit

Permalink
chore: Build Docker images (#6533)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yserz authored May 6, 2019
1 parent 659704a commit c1bc4bf
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 28 deletions.
7 changes: 5 additions & 2 deletions .copyconfigrc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const pkg = require('./package.json');
const appConfigPkg = require('./app-config/package.json');
const {execSync} = require('child_process');
const path = require('path');

const currentBranch = execSync('git rev-parse --abbrev-ref HEAD')
.toString()
.trim();
const configurationEntry = `wire-web-config-default-${currentBranch === 'prod' ? 'prod' : 'staging'}`;
const repositoryUrl = pkg.dependencies[configurationEntry];
const suffix =
process.env.DISTRIBUTION !== 'wire' ? process.env.DISTRIBUTION : currentBranch === 'prod' ? 'prod' : 'staging';
const configurationEntry = `wire-web-config-default-${suffix}`;
const repositoryUrl = appConfigPkg.dependencies[configurationEntry];

module.exports = {
files: {
Expand Down
45 changes: 36 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@ dist: trusty
env:
global:
# GH_TOKEN
- secure: "Fpze1ZU5I5MryhhWsJlcQJ61D4wvscUMfaOV0O1hczv880jhFT0Hisy47bn1stUfWyLkEMYOCxDonceEiC3j5fc0qg4HXm1fqR1dfqe+3uAbXvTPd6fbzb8ZhdOOpzvIyC2vUgB0qxh+b6/KFmJ7A1L0Bjz2lpYUhwgHnyHFEsi1cMKwFJLwdOZi6h/BglrbLgQgQGYIvhI76ZEH+RGvjNKeFENxd1/hht2j447iVRe8nePp0jf4PUn0WlFXvoETP1yP+Kk/oZyhx7YNg3jRA0Uue4I1HaVyPI0yz/nKY5W7CBjkSvqI78omCQ3YIXQhqdzGLi0JyR4wj4wwBZGGuTTCo1fqRW4OjfgA4A/PyOgHG3OfvZzdr/NI+qF22XCJEx+dzvbQDn7WYgsxjHdjoBd3QZpZlB3sF223zTpueL7XoaFnSqM92SvuUSvhPceDvkUyS3eJJ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sDibBSx/u9KlCqRYu7J8rRhZD0EvQBGK14dnqV8Tb0Z7RkiCxGc+zjTXRetLo4soyVA0C5HzEdG1wSWnCRN7mwOptdcT7HuNLVU407MGGLCJaCONDhzcDiXVy5J1XyAn+amIMgSUgiBRkTaWE='
# DOCKER_PASSWORD
- secure: 'e7ubyFQ5K6rQAJCYX7iuUZMJW7V9XKkUFqEuGcsA0/UowIPvytpQRTnrqp22F6a5lIp1/EvcZ1luglgxkgYX/G4FeVV7F2WjIwh0sMHO6ix/P14N7Arp2vtRllg7jqMT/0QRuXLApRBG0jvs8FhiGtXFeeKP4UgiRdLXUId1vEW8MPDvPzh4yzl1ZgkaeVswid0S0pRDEeue08mkwC5WS9TL/Ns5jvGAr4fgeibpoGRIeE7gCxGVy6yjXq+qXRoL9MCvkloKUfyrwhOtq0vFlPigHsssxx3KUTjOanDjqhQasVGqMFMA0c9jBGLotDkF1245lv9ie9DD6MmnmcYHLVXXdcBH+jzOppAJ9iqA6ftPiRU6FPh7zDNVfjc8laI6sj3A/KbAsa0lin/H2dROfjB1AcGISh4RdzLFWILUV6fob842AU+6KcVE3qhSoL/Q6z3B/9lX4v20NgBnM68u4wjiwziOVfeaBxnEN+btseG193IpzSEU5hUDZzc9s0c+HwytuDDYq8Pa3MeJ69ZKcrYVteUyW0W+pCivlGwJSNPdT3iruGrWfBA1YAvazQM1mDg2CsIJBntO9m0SeW2hOil0j7g9nrOINKvh3C4FQ6VqT14eILhHPUGoFwarxz9rLRQwjtbzR6VZpCBorBKWgsNgZ5HA7jjdTDhQySS/0og='
matrix:
- DISTRIBUTION="$DISTRIBUTION_1"
- DISTRIBUTION="wire"

# http://docs.travis-ci.com/user/languages/javascript-with-nodejs/
language: node_js
node_js:
- "10"
- '10'

# http://docs.travis-ci.com/user/gui-and-headless-browsers/
before_install:
- echo -e "machine github.com\n login $GH_TOKEN" > ~/.netrc
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

Expand All @@ -32,16 +40,32 @@ before_script:
- npm rebuild node-sass

after_script:
- "bash <(curl -s https://codecov.io/bash) -f ./docs/coverage/lcov.info"
- 'bash <(curl -s https://codecov.io/bash) -f ./docs/coverage/lcov.info'

notifications:
email: false

# http://docs.travis-ci.com/user/deployment/
after_success:
- if [[ "${TRAVIS_BRANCH}" =~ ^(dev|edge)$ ]] && [ "${TRAVIS_PULL_REQUEST}" == "false" ]; then yarn build:prod; fi
- if [[ "${TRAVIS_TAG}" =~ .*-staging.* ]]; then yarn build:prod; fi
- if [ "$TRAVIS_BRANCH" == "prod" ]; then yarn build:prod || { echo 'contents of npm-debug.log:' && cat /home/travis/build/wireapp/wire-webapp/npm-debug.log && exit 1; } fi
- |
if [[ "${TRAVIS_TAG}" =~ .*-staging.* ]]; then
yarn build:prod
if [ "$DISTRIBUTION" == "wire" ]; then
yarn docker '' staging
else
yarn docker "$DISTRIBUTION" staging
fi
fi
- |
if [ "$TRAVIS_BRANCH" == "prod" ]; then
yarn build:prod || { echo 'contents of npm-debug.log:' && cat /home/travis/build/wireapp/wire-webapp/npm-debug.log && exit 1; }
if [ "$DISTRIBUTION" == "wire" ]; then
yarn docker '' production
else
yarn docker "$DISTRIBUTION" production
fi
fi
# https://github.com/travis-ci/dpl#elastic-beanstalk
deploy:
Expand All @@ -60,6 +84,7 @@ deploy:
on:
repo: wireapp/wire-webapp
branch: edge
condition: $DISTRIBUTION = wire

# https://wire-webapp-dev.zinfra.io/
- provider: elasticbeanstalk
Expand All @@ -76,6 +101,7 @@ deploy:
on:
repo: wireapp/wire-webapp
branch: dev
condition: $DISTRIBUTION = wire

# https://wire-webapp-rc.zinfra.io/
- provider: elasticbeanstalk
Expand All @@ -91,7 +117,7 @@ deploy:
bucket_name: wire-webapp-builds
on:
tags: true
condition: $TRAVIS_TAG =~ .*-staging.*
condition: $TRAVIS_TAG =~ .*-staging.* AND $DISTRIBUTION = wire

# https://wire-webapp-staging.zinfra.io/
- provider: elasticbeanstalk
Expand All @@ -107,7 +133,7 @@ deploy:
bucket_name: wire-webapp-builds
on:
tags: true
condition: $TRAVIS_TAG =~ .*-staging.*
condition: $TRAVIS_TAG =~ .*-staging.* AND $DISTRIBUTION = wire

# https://wire-webapp-prod.wire.com/
- provider: elasticbeanstalk
Expand All @@ -124,6 +150,7 @@ deploy:
on:
repo: wireapp/wire-webapp
branch: prod
condition: $DISTRIBUTION = wire

after_deploy:
- |
Expand Down
21 changes: 8 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
FROM node:10-alpine

# For some extra dependencies...
RUN apk add --no-cache dumb-init git bash python
RUN apk add --no-cache dumb-init git bash

# This is required to build some of the webapp modules
RUN echo '{ "allow_root": true }' > /root/.bowerrc
COPY /server .
COPY /run.sh .
COPY /env.defaults .
ENV NODE_PATH=/node_modules
ENV PATH=$PATH:/node_modules/.bin

COPY . /src
ENV NODE_PATH=/src/node_modules
ENV PATH=$PATH:/src/node_modules/.bin

ARG WIRE_CONFIGURATION_REPOSITORY
ARG WIRE_CONFIGURATION_EXTERNAL_DIR

WORKDIR /src
RUN yarn && yarn build:prod
RUN yarn

EXPOSE 8080

ENTRYPOINT ["dumb-init", "--", "/bin/bash", "/src/run.sh"]
ENTRYPOINT ["dumb-init", "--", "/bin/bash", "/run.sh"]
7 changes: 7 additions & 0 deletions app-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": {
"wire-web-config-default-ey": "https://github.com/wireapp/wire-web-config-ey.git#v0.18.1-0",
"wire-web-config-default-prod": "https://github.com/wireapp/wire-web-config-wire#v0.17.27-0",
"wire-web-config-default-staging": "https://github.com/wireapp/wire-web-config-default#v0.17.27"
}
}
64 changes: 64 additions & 0 deletions bin/push_docker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env node

/*
* Wire
* Copyright (C) 2019 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

const child = require('child_process');
const appConfigPkg = require('../app-config/package.json');
const pkg = require('../package.json');
const {execSync} = require('child_process');

const currentBranch = execSync('git rev-parse --abbrev-ref HEAD')
.toString()
.trim();

const distributionParam = process.argv[2];
const stageParam = process.argv[3];
const suffix = distributionParam ? `-${distributionParam}` : '';
const stage = stageParam ? `-${stageParam}` : '';
const buildCounter = process.env.TRAVIS_BUILD_NUMBER || 'BUILD_NUMBER';
const commitSha = process.env.TRAVIS_COMMIT || 'COMMIT_ID';
const commitShaLength = 7;
const commitShortSha = commitSha.substring(0, commitShaLength - 1);
const configurationEntry = `wire-web-config-default${
suffix ? suffix : currentBranch === 'prod' ? '-prod' : '-staging'
}`;
const dependencies = {
...appConfigPkg.dependencies,
...appConfigPkg.devDependencies,
...appConfigPkg.peerDependencies,
...appConfigPkg.optionalDependencies,
};

const configVersion = dependencies[configurationEntry].split('#')[1];
const dockerRegistryDomain = 'quay.io';
const dockerImageTag = `${dockerRegistryDomain}/wire/webapp${suffix}:${buildCounter}-${
pkg.version
}-${commitShortSha}-${configVersion}${stage}`;

child.execSync(
`echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin ${dockerRegistryDomain}`,
{stdio: 'inherit'}
);
child.execSync(
`docker build . -t ${dockerImageTag} &&
docker push ${dockerImageTag} &&
docker logout ${dockerRegistryDomain}`,
{stdio: 'inherit'}
);
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
"underscore": "1.9.1",
"url-search-params-polyfill": "5.1.0",
"uuidjs": "4.2.1",
"webrtc-adapter": "6.4.8",
"wire-web-config-default-prod": "https://github.com/wireapp/wire-web-config-wire#v0.17.27-0",
"wire-web-config-default-staging": "https://github.com/wireapp/wire-web-config-default#v0.17.27"
"webrtc-adapter": "6.4.8"
},
"devDependencies": {
"@babel/core": "7.4.4",
Expand Down Expand Up @@ -196,6 +194,7 @@
"configure": "copy-config",
"deploy": "yarn && yarn build:prod && eb deploy",
"dist": "grunt build",
"docker": "node bin/push_docker.js",
"fix": "yarn fix:assets && yarn fix:js && yarn fix:ts",
"fix:assets": "yarn prettier --write && yarn stylelint",
"fix:js": "yarn lint:js --fix",
Expand All @@ -222,6 +221,7 @@
"translate:merge": "yarn bundle:prod && node ./bin/translations_normalize.js",
"translate:extract": "i18next-scanner 'src/{page,script}/**/*.{js,html,htm}'"
},
"version": "0.1.0",
"private": true,
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

port=${NODE_PORT:-8080}

PORT=$port node /src/server/dist/index.js
PORT=$port node /dist/index.js

0 comments on commit c1bc4bf

Please sign in to comment.