Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ci drone #529

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
82 changes: 82 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
kind: pipeline
type: docker
name: build

steps:
- name: api docker build
image: plugins/docker
settings:
dockerfile: api/Dockerfile
context: api
repo: docker-hub.unepgrid.ch/mapx/mx-api-node
registry: docker-hub.unepgrid.ch
username:
from_secret: docker_username
password:
from_secret: docker_password
tags:
- latest
- 1.6.66-alpine

- name: app npm run prod
image: node:8-alpine
commands:
- apk add git python build-base
- cd app/
- npm ci
- npm run prod

- name: app docker build
image: plugins/docker
settings:
dockerfile: app/Dockerfile
context: app
repo: docker-hub.unepgrid.ch/mapx/mx-app-shiny
registry: docker-hub.unepgrid.ch
username:
from_secret: docker_username
password:
from_secret: docker_password
tags:
- latest
- 1.6.66-debian

trigger:
ref:
- refs/tags/*

---
kind: pipeline
type: docker
name: api test

steps:
- name: api
image: docker-hub.unepgrid.ch/mapx/mx-api-node:1.6.66-alpine
commands:
- set -o allexport; source mapx.dev.default_env; set +o allexport
- while [ "`PGPASSWORD=$POSTGRES_PASSWORD psql -h pg -U postgres -l 2>/dev/null | grep mapx_test | wc -l`" = "0" ]; do echo "Waiting service 'pg'..."; sleep 5; done
- echo "Service 'pg' ready!..."
- cd api/
- npm ci
- npm run test

depends_on:
- build

services:
- name: pg
image: mdillon/postgis:10-alpine
commands:
- set -o allexport; source mapx.dev.default_env; set +o allexport
- cp -a /drone/src/pg/init/* /docker-entrypoint-initdb.d/
- docker-entrypoint.sh postgres
- name: redis
image: redis:alpine
ports:
- 6379
commands:
- set -o allexport; source mapx.dev.default_env; set +o allexport
- mkdir -p /usr/local/etc/redis/; cp -a redis.conf /usr/local/etc/redis/redis.conf
- redis-server /usr/local/etc/redis/redis.conf
1 change: 0 additions & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ VOLUME /shared
EXPOSE 3030

CMD ["node","index.js"]

4 changes: 3 additions & 1 deletion api/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ var Mocha = require('mocha');
var mocha = new Mocha();
mocha.addFile('test/testMiscellaneous');
mocha.addFile('test/testGetProjects');
mocha.run();
mocha.run(function() {
process.exit();
});
1 change: 0 additions & 1 deletion app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ COPY . /srv/shiny-server/mapx
COPY ./start_mapx.sh /usr/bin/start_mapx.sh

CMD ["sh","/usr/bin/start_mapx.sh"]

4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
},
"scripts": {
"test": "-",
"prod": "npm run build_dict && webpack --config ./webpack/webpack.prod.js",
"dev": "webpack --watch --config ./webpack/webpack.dev.js",
"prod": "npm run build_dict && npx webpack --config ./webpack/webpack.prod.js",
"dev": "npx webpack --watch --config ./webpack/webpack.dev.js",
"build_dict": "node ./src/node/build_dict.js config_dict.json",
"lint": "eslint"
},
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
app:
env_file: mapx.dev.env
build: ./app/.
image: fredmoser/mx-app-shiny:1.6.66-debian
image: docker-hub.unepgrid.ch/mapx/mx-app-shiny:1.6.66-debian
restart: always
ports:
- 3838
Expand All @@ -44,7 +44,7 @@ services:
api:
env_file: mapx.dev.env
build: ./api/.
image: fredmoser/mx-api-node:1.6.66-alpine
image: docker-hub.unepgrid.ch/mapx/mx-api-node:1.6.66-alpine
restart: always
ports:
- 3030
Expand Down
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,8 @@ Run tests within the development container:
```
$ docker-compose exec api sh
$ cd /apidev
$ npm run
$ npm run test
```

# Build
Version 1.6.66 [![Build Status](https://cloud.drone.io/api/badges/trepmag/map-x-mgl/status.svg?pipeline=api%20test&ref=refs/tags/1.6.66)](https://cloud.drone.io/trepmag/map-x-mgl)
75 changes: 75 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

#
# Script to build and push new image in remote docker repository
#
BRANCH=master
REMOTE=github
NEW_VERSION=$1
OLD_VERSION=`cat version.txt`
echo $NEW_VERSION
FG_GREEN="\033[32m"
FG_NORMAL="\033[0m"
CHANGES_CHECK=$(git status --porcelain | wc -l)
DIR_APP=app
DIR_CUR=$(pwd)
CUR_HASH=$(git rev-parse HEAD)

USAGE="Usage : bash build.sh $OLD_VERSION"

if [ $CHANGES_CHECK -gt 0 ]
then
echo "This project as uncommited changes, stop here"
exit 1
fi

if [ -z "$NEW_VERSION" ] || [ "$NEW_VERSION" == "$OLD_VERSION" ]
then
echo "Wrong or missing version. Old version version = $OLD_VERSION new version = $NEW_VERSION"
echo "$USAGE"
exit 1
fi

#
# Update version + verification
#

echo "Update package.json"
REP_PACKAGE_VERSION='s/"version": "'"$OLD_VERSION"'"/"version": "'"$NEW_VERSION"'"/g'
perl -pi -e "$REP_PACKAGE_VERSION" ./app/package.json
perl -pi -e "$REP_PACKAGE_VERSION" ./api/package.json
echo "Update version.txt"
REP_VERSION='s/'"$OLD_VERSION"'/'"$NEW_VERSION"'/g'
perl -pi -e "$REP_VERSION" version.txt
perl -pi -e "$REP_VERSION" ./app/src/html/index.html
echo "Update docker-compose.yml"
REP_API_TAG='s/mx-api-node:'"$OLD_VERSION"'-alpine/mx-api-node:'"$NEW_VERSION"'-alpine/g'
REP_APP_TAG='s/mx-app-shiny:'"$OLD_VERSION"'-debian/mx-app-shiny:'"$NEW_VERSION"'-debian/g'
perl -pi -e $REP_API_TAG ./docker-compose.yml
perl -pi -e $REP_APP_TAG ./docker-compose.yml
echo "Update .drone.yml"
REP_DRONE_TAG='s/'"$OLD_VERSION"'-/'"$NEW_VERSION"'-/g'
perl -pi -e $REP_DRONE_TAG ./.drone.yml
echo "Update readme.md"
REP_README_TAG='s/Version '"$OLD_VERSION"'-/Version '"$NEW_VERSION"'-/g'
perl -pi -e $REP_README_TAG ./readme.md

git --no-pager diff --minimal

echo "Verify git diff of versioning changes. Continue (npm prod, build + push) ? [YES/NO]"
read confirm_diff

if [ "$confirm_diff" != "YES" ]
then
echo "Stop here, stash changes. rollback to $CUR_HASH "
git stash
exit 1
fi

echo "Commit and push version $NEW_VERSION tag and text"
git add .
git commit -m "auto build version $NEW_VERSION"
git tag $NEW_VERSION
git push $REMOTE $BRANCH --tags

echo "Done"