Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Docker deployments using Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
fboucquez authored Jul 30, 2020
1 parent 41b5bc9 commit ddf281c
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Dockerfile
.dockerignore
docker.sh

.idea
.vscode
.git
.gitignore
.travis.yml

*/node_modules
*/_build

**/npm-*.log
**/yarn-*.log
**/catapult-*.log
18 changes: 16 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ language: node_js

node_js:
- "12"

services:
- docker
addons:
apt:
sources:
Expand All @@ -29,4 +30,17 @@ before_script:
- sudo systemctl start mongod
- sh yarn_setup.sh

script: cd ${SUBPROJECT} && yarn run lint && yarn run test:travis
script: cd ${SUBPROJECT} && yarn run lint && yarn run test:travis && cd ..

jobs:
include:
- stage: docker alpha deploy
env:
- SUBPROJECT=rest
script: /bin/sh docker.sh
if: branch = master AND type != pull_request
- stage: docker release deploy
env:
- SUBPROJECT=rest
script: /bin/sh docker.sh --release
if: tag IS present
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:12.18.1-alpine
RUN apk add --update\
python \
python3 \
build-base \
zeromq-dev \
&& rm -rf /var/cache/apk/*
WORKDIR /app
COPY . /app/catapult-rest
RUN cd catapult-rest \
&& ./yarn_setup.sh
RUN cd catapult-rest/rest \
&& yarn build
WORKDIR /app/catapult-rest/rest
44 changes: 44 additions & 0 deletions docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh

if [ "${DOCKER_IMAGE_NAME}" = "" ]
then
echo "Docker deployment error. Env DOCKER_IMAGE_NAME has not been provided"
exit 128
fi

if [ "${DOCKER_USERNAME}" = "" ]
then
echo "Docker deployment error. Env DOCKER_USERNAME has not been provided"
exit 128
fi

if [ "${DOCKER_PASSWORD}" = "" ]
then
echo "Docker deployment error. Env DOCKER_PASSWORD has not been provided"
exit 128
fi

echo "Login into docker..."
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

cd rest
CURRENT_VERSION=$(npm run version --silent)
cd ..

if [ "$1" = "--release" ]
then
VERSION="${CURRENT_VERSION}"
else
VERSION="${CURRENT_VERSION}-alpha"
fi

echo "Creating image ${DOCKER_IMAGE_NAME}:${VERSION}"
docker build -t "${DOCKER_IMAGE_NAME}:${VERSION}" .
docker images

# Quick test, the expected error is ENOENT: no such file or directory, open '../resources/rest.json'
echo "Testing image ${DOCKER_IMAGE_NAME}:${VERSION}. NOTE: ENOENT: no such file or directory, open '../resources/rest.json is expected"
docker run --rm "${DOCKER_IMAGE_NAME}:${VERSION}" npm start

echo "Pushing image ${DOCKER_IMAGE_NAME}:${VERSION}"
docker push "${DOCKER_IMAGE_NAME}:${VERSION}"
1 change: 1 addition & 0 deletions rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"clean": "rimraf _build && mkdir _build",
"build": "ncp src/ _build",
"rebuild": "npm run clean && npm run build",
"version": "echo $npm_package_version",
"start": "node _build/index.js",
"start:debug": "node src/index.js",
"test": "mocha --full-trace --recursive",
Expand Down

0 comments on commit ddf281c

Please sign in to comment.