diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e661a61ab7b..3c8e1db7bb6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,34 +1,93 @@ -name: CI test +name: CI test and publish Docker image -on: [push, pull_request] +on: + push: + branches: + - master + - dev + pull_request: + branches: + - master + - dev jobs: - build: - - runs-on: ubuntu-16.04 - + test: + name: Run Tests + runs-on: ubuntu-latest strategy: matrix: - node-version: [12.x] + node-version: [12.x, 14.x] + mongodb-version: [4.2, 4.4] + + steps: + - name: Git Checkout + uses: actions/checkout@v2 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Start MongoDB ${{ matrix.mongodb-version }} + uses: supercharge/mongodb-github-action@1.3.0 + with: + mongodb-version: ${{ matrix.mongodb-version }} + + - name: Install dependencies + run: npm install + - name: Run Tests + run: npm run-script test-ci + - name: Send Coverage + run: npm run-script coverage + + publish_dev: + name: Publish dev branch to Docker Hub + needs: test + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/dev' + env: + DOCKER_IMAGE: nightscout/cgm-remote-monitor + steps: + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} + - name: Clean git Checkout + if: success() + uses: actions/checkout@v2 + - name: Build, tag and push the dev Docker image + if: success() + run: | + docker build --no-cache=true -t ${{ env.DOCKER_IMAGE }}:dev_${{ github.sha }} . + docker image push ${{ env.DOCKER_IMAGE }}:dev_${{ github.sha }} + docker tag ${{ env.DOCKER_IMAGE }}:dev_${{ github.sha }} ${{ env.DOCKER_IMAGE }}:latest_dev + docker image push ${{ env.DOCKER_IMAGE }}:latest_dev + publish_master: + name: Publish master branch to Docker Hub + needs: test + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/master' + env: + DOCKER_IMAGE: nightscout/cgm-remote-monitor steps: - - uses: actions/checkout@v1 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: Install dependencies - run: npm install - - name: Install MongoDB - run: | - wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list - sudo apt-get update - sudo apt-get install -y mongodb-org - sudo apt-get install -y --allow-downgrades mongodb-org=4.4.0 mongodb-org-server=4.4.0 mongodb-org-shell=4.4.0 mongodb-org-mongos=4.4.0 mongodb-org-tools=4.4.0 - - name: Start MongoDB - run: sudo systemctl start mongod - - name: Run Tests - run: npm run-script test-ci - - name: Send Coverage - run: npm run-script coverage + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} + - name: Clean git Checkout + if: success() + uses: actions/checkout@v2 + - name: get-npm-version + if: success() + id: package-version + uses: martinbeentjes/npm-get-version-action@master + - name: Build, tag and push the master Docker image + if: success() + run: | + docker build --no-cache=true -t ${{ env.DOCKER_IMAGE }}:${{ steps.package-version.outputs.current-version }} . + docker image push ${{ env.DOCKER_IMAGE }}:${{ steps.package-version.outputs.current-version }} + docker tag ${{ env.DOCKER_IMAGE }}:${{ steps.package-version.outputs.current-version }} ${{ env.DOCKER_IMAGE }}:latest + docker image push ${{ env.DOCKER_IMAGE }}:latest diff --git a/.nvmrc b/.nvmrc index 89da89da65c..19c4c189d36 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -10.16.0 \ No newline at end of file +14.15.3 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c62652d2a13..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,30 +0,0 @@ -sudo: required -dist: xenial - -node_js-steps: &node_js-steps - language: node_js - before_install: - - if [[ `npm --version` != "6.4.1" ]]; then npm install -g npm@latest; npm --version; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi - # https://github.com/Homebrew/homebrew-core/issues/26358 - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew unlink python; fi - # "brew install" can succeed but return 1 if it has "caveats". - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install mongodb || true; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew services start mongodb; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install docker || true; fi - script: make travis - after_success: - - nvm version - - if [[ ! -z "$DOCKER_USER" ]]; then docker login -u ${DOCKER_USER} -p ${DOCKER_PASS} && git checkout -- . && git clean -fd . && make docker_release; fi - after_script: make report - services: - - mongodb - - docker -matrix: - allow_failures: - node_js: "node" - include: - - node_js: "10" - <<: *node_js-steps - - node_js: "12" - <<: *node_js-steps diff --git a/Dockerfile.example b/Dockerfile similarity index 76% rename from Dockerfile.example rename to Dockerfile index 89a43f43c15..495d461701d 100644 --- a/Dockerfile.example +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM node:10-alpine +FROM node:14.15.3-alpine -MAINTAINER Nightscout Contributors +LABEL maintainer="Nightscout Contributors" RUN mkdir -p /opt/app ADD . /opt/app diff --git a/Makefile b/Makefile index 1ca626ab88c..46a3c462131 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ MONGO_SETTINGS=MONGO_CONNECTION=${MONGO_CONNECTION} \ # coverage reporter's ability to instrument the tests correctly. # Hard coding it to the local with our pinned version is bigger for # initial installs, but ensures a consistent environment everywhere. -# On Travis, ./node_modules/.bin and other `nvm` and `npm` bundles are +# On GA, ./node_modules/.bin and other `nvm` and `npm` bundles are # inserted into the default `$PATH` enviroinment, making pointing to # the unwrapped mocha executable necessary. MOCHA=./node_modules/mocha/bin/_mocha @@ -25,7 +25,7 @@ ANALYZED=./coverage/lcov.info # Following token deprecated # export CODACY_REPO_TOKEN=e29ae5cf671f4f918912d9864316207c -DOCKER_IMAGE=nightscout/cgm-remote-monitor-travis +DOCKER_IMAGE=nightscout/cgm-remote-monitor all: test @@ -48,7 +48,7 @@ test_onebyone: test: ${MONGO_SETTINGS} ${MOCHA} --timeout 30000 --exit --bail -R tap ${TESTS} -travis: +ci_tests: python -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL); fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);' # NODE_ENV=test ${MONGO_SETTINGS} \ # ${ISTANBUL} cover ${MOCHA} --report lcovonly -- --timeout 5000 -R tap ${TESTS} @@ -57,28 +57,25 @@ travis: docker_release: # Get the version from the package.json file $(eval DOCKER_TAG=$(shell cat package.json | jq '.version' | tr -d '"')) - $(eval NODE_VERSION=$(shell cat .nvmrc)) + $(eval BRANCH=$(lastword $(subst /, ,$(GITHUB_REF)))) # - # Create a Dockerfile that contains the correct NodeJS version - cat Dockerfile.example | sed -e "s/^FROM node:.*/FROM node:${NODE_VERSION}/" > Dockerfile # # Rebuild the image. We do this with no-cache so that we have all security upgrades, # since that's more important than fewer layers in the Docker image. docker build --no-cache=true -t $(DOCKER_IMAGE):$(DOCKER_TAG) . - # Push an image to Docker Hub with the version from package.json: - docker push $(DOCKER_IMAGE):$(DOCKER_TAG) # # Push the master branch to Docker hub as 'latest' - if [ "$(TRAVIS_BRANCH)" = "master" ]; then \ + if [ "$(BRANCH)" = "master" ]; then \ docker tag $(DOCKER_IMAGE):$(DOCKER_TAG) $(DOCKER_IMAGE):latest && \ + docker push $(DOCKER_IMAGE):$(DOCKER_TAG) docker push $(DOCKER_IMAGE):latest; \ fi # # Push the dev branch to Docker Hub as 'latest_dev' - if [ "$(TRAVIS_BRANCH)" = "dev" ]; then \ + if [ "$(BRANCH)" = "dev" ]; then \ docker tag $(DOCKER_IMAGE):$(DOCKER_TAG) $(DOCKER_IMAGE):latest_dev && \ + docker push $(DOCKER_IMAGE):$(DOCKER_TAG) docker push $(DOCKER_IMAGE):latest_dev; \ fi - rm -f Dockerfile -.PHONY: all coverage docker_release report test travis +.PHONY: all coverage docker_release report test ci_tests