From 97ed5e80e6127951c5d09271ea1c2f0f46ef1532 Mon Sep 17 00:00:00 2001 From: Noam Gal Date: Fri, 8 May 2020 23:13:22 +0300 Subject: [PATCH] Switching to official Docker GitHub Actions run actions on every push and pr --- .dockerignore | 1 + .eslintrc.js | 36 +++++----- .github/workflows/dockerpublish.yml | 68 +++++-------------- Dockerfile => docker/Dockerfile | 0 .../docker-compose.yaml | 4 +- package.json | 1 - src/app.js | 7 +- src/logger.js | 2 +- src/osm2gpx.js | 4 +- 9 files changed, 41 insertions(+), 82 deletions(-) rename Dockerfile => docker/Dockerfile (100%) rename docker-compose.yaml => docker/docker-compose.yaml (74%) diff --git a/.dockerignore b/.dockerignore index 6cc7b8d..82e0afd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -36,3 +36,4 @@ **/.node_repl_history .git +.github diff --git a/.eslintrc.js b/.eslintrc.js index b283c22..6b1033a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,13 +1,11 @@ module.exports = { - plugins: [ - 'standard', - 'prettier', - 'import', - ], + plugins: ['standard'], extends: [ 'eslint:recommended', + // Adds 'promise'/'import'/'node' plugins and configurations 'standard', - 'prettier', + // Adds 'prettier' plugin + 'plugin:prettier/recommended', 'prettier/standard', ], parserOptions: { @@ -19,18 +17,18 @@ module.exports = { es6: true, }, rules: { - // fixable - errors - 'prettier/prettier': [ + // Fixable - errors + 'one-var': [ 'error', + { + const: 'never', + let: 'never', + }, ], - 'one-var': ['error', { - const: 'never', - let: 'never', - }], 'dot-notation': 'error', 'no-else-return': ['error', {allowElseIf: false}], 'capitalized-comments': 'error', - //'linebreak-style': 'off', + // 'linebreak-style': 'off', 'lines-between-class-members': 'error', 'multiline-comment-style': 'error', 'no-lonely-if': 'error', @@ -46,12 +44,12 @@ module.exports = { 'prefer-template': 'error', 'sort-imports': 'error', - // non-fixable - warnings + // Non-fixable - warnings 'no-await-in-loop': 'warn', 'array-callback-return': 'warn', 'block-scoped-var': 'warn', - //'class-methods-use-this': 'warn', - 'complexity': 'warn', + // 'class-methods-use-this': 'warn', + complexity: 'warn', 'consistent-return': 'warn', 'default-case': 'warn', 'guard-for-in': 'warn', @@ -60,13 +58,13 @@ module.exports = { 'no-implicit-globals': 'warn', 'no-invalid-this': 'warn', 'no-loop-func': 'warn', - //'no-magic-numbers': 'warn', + // 'no-magic-numbers': 'warn', 'no-param-reassign': 'warn', 'no-script-url': 'warn', 'no-useless-concat': 'warn', 'no-void': 'warn', 'no-warning-comments': 'warn', - 'radix': 'warn', + radix: 'warn', 'require-await': 'warn', 'init-declarations': 'warn', 'no-catch-shadow': 'warn', @@ -81,7 +79,7 @@ module.exports = { 'consistent-this': 'warn', 'func-name-matching': 'warn', 'func-names': 'warn', - 'func-style': ['warn', 'declaration', {"allowArrowFunctions": true}], + 'func-style': ['warn', 'declaration', {allowArrowFunctions: true}], 'line-comment-position': 'warn', 'max-depth': 'warn', 'max-nested-callbacks': 'warn', diff --git a/.github/workflows/dockerpublish.yml b/.github/workflows/dockerpublish.yml index 4bd55d4..188a1f1 100644 --- a/.github/workflows/dockerpublish.yml +++ b/.github/workflows/dockerpublish.yml @@ -1,20 +1,6 @@ name: Docker -on: - push: - # Publish `master` as Docker `latest` image. - branches: - - master - - # Publish `v1.2.3` tags as releases. - tags: - - v* - - # Run tests for any PRs. - pull_request: - -env: - IMAGE_NAME: osmexport +on: [push, pull_request] jobs: # Run tests. @@ -27,52 +13,30 @@ jobs: - name: Run tests run: | - if [ -f docker-compose.test.yml ]; then - docker-compose --file docker-compose.test.yml build - docker-compose --file docker-compose.test.yml run sut + if [ -f docker/docker-compose.test.yml ]; then + docker-compose --file docker/docker-compose.test.yml build + docker-compose --file docker/docker-compose.test.yml run sut else - docker build . --file Dockerfile + docker build --file docker/Dockerfile . fi # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ push: - # Ensure test job passes before pushing image. needs: test runs-on: ubuntu-latest - if: github.event_name == 'push' steps: - uses: actions/checkout@v2 - - - name: Set image id - run: | - IMAGE_ID="docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME" - IMAGE_ID=$(echo ${IMAGE_ID} | tr '[A-Z]' '[a-z]') - echo "::set-env name=IMAGE_ID::${IMAGE_ID}" - - - name: Build image - run: | - # Strip git ref prefix from version - BRANCH_NAME=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then - # Strip "v" prefix from tag name - VERSION=$(echo $BRANCH_NAME | sed -e 's/^v//') - LATEST_TAG="--tag ${IMAGE_ID}:latest" - else - FULL_SHA=${{ github.sha }} - SHA7=${FULL_SHA:0:7} - VERSION="${BRANCH_NAME}_${SHA7}" - LATEST_TAG="" - fi - - TAG="--tag ${IMAGE_ID}:${VERSION}" - echo "docker build . --file Dockerfile ${TAG} ${LATEST_TAG}" - docker build . --file Dockerfile ${TAG} ${LATEST_TAG} - - - name: Log into registry - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin - - name: Push image - run: docker push ${IMAGE_ID} + - name: Build and push Docker images + uses: docker/build-push-action@v1.1.0 + with: + repository: atgardner/osmexport/osmexport + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: docker.pkg.github.com + dockerfile: docker/Dockerfile + tag_with_ref: true + tag_with_sha: true + add_git_labels: true diff --git a/Dockerfile b/docker/Dockerfile similarity index 100% rename from Dockerfile rename to docker/Dockerfile diff --git a/docker-compose.yaml b/docker/docker-compose.yaml similarity index 74% rename from docker-compose.yaml rename to docker/docker-compose.yaml index 2386c14..7e0202a 100644 --- a/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -2,8 +2,8 @@ version: '3.7' services: osmexport: build: - context: . - dockerfile: Dockerfile + context: ../ + dockerfile: docker/Dockerfile image: noamgal/osmexport:latest container_name: osmexport ports: diff --git a/package.json b/package.json index 6df3877..9b9661a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "cmd": "node commandLine.js" }, "author": "", - "type": "module", "license": "ISC", "devDependencies": { "chai": "^4.2.0", diff --git a/src/app.js b/src/app.js index 1e2e9d7..4fdda66 100644 --- a/src/app.js +++ b/src/app.js @@ -62,7 +62,7 @@ app.get('/osm2gpx', async ({query, query: {relationId}, visitor}, res) => { const safeFileName = encodeURI( slug(fileName, { // Replace spaces with replacement - replacement: c => c, + replacement: (c) => c, // Replace unicode symbols or not symbols: false, // (optional) regex to remove characters @@ -84,10 +84,7 @@ app.get('/osm2gpx', async ({query, query: {relationId}, visitor}, res) => { const end = moment().diff(start); sendTiming(visitor, 'failureTime', end); sendEvent(visitor, 'Error', `${relationId} - ${error}`); - res - .set('Content-Type', 'text/plain') - .status(500) - .send(error.stack); + res.set('Content-Type', 'text/plain').status(500).send(error.stack); } }); diff --git a/src/logger.js b/src/logger.js index 18c199c..015e3b2 100644 --- a/src/logger.js +++ b/src/logger.js @@ -1,7 +1,7 @@ 'use strict'; import winston from 'winston'; -// import {createLogger, format, transports} from 'winston'; +// Import {createLogger, format, transports} from 'winston'; const {combine, timestamp, label, simple} = winston.format; diff --git a/src/osm2gpx.js b/src/osm2gpx.js index 640bf6b..df3007f 100644 --- a/src/osm2gpx.js +++ b/src/osm2gpx.js @@ -75,7 +75,7 @@ function addMarkers({geometry: {coordinates, type}}, markerDiff) { let prevDistance = 0; let prevMarker = 0; let prevLatLon = 0; - ways.forEach(way => { + ways.forEach((way) => { way.forEach(([lon, lat]) => { if (prevLatLon) { const latLon = new LatLon(lat, lon); @@ -110,7 +110,7 @@ export async function getRelation({ reverse, }) { const geoJson = await getFullRelation(relationId); - const relation = geoJson.features.find(f => f.id.startsWith('relation')); + const relation = geoJson.features.find((f) => f.id.startsWith('relation')); if (reverse) { relation.geometry.coordinates.reverse(); }