Skip to content

Commit

Permalink
Switching to official Docker GitHub Actions
Browse files Browse the repository at this point in the history
run actions on every push and pr
  • Loading branch information
ATGardner committed May 8, 2020
1 parent 6836c98 commit 97ed5e8
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 82 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@
**/.node_repl_history

.git
.github
36 changes: 17 additions & 19 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
68 changes: 16 additions & 52 deletions .github/workflows/dockerpublish.yml
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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/[email protected]
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
File renamed without changes.
4 changes: 2 additions & 2 deletions docker-compose.yaml → docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"cmd": "node commandLine.js"
},
"author": "",
"type": "module",
"license": "ISC",
"devDependencies": {
"chai": "^4.2.0",
Expand Down
7 changes: 2 additions & 5 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/logger.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/osm2gpx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 97ed5e8

Please sign in to comment.