Skip to content

Commit

Permalink
Merge pull request #431 from swrlab/dev/update-1.4.0
Browse files Browse the repository at this point in the history
Update v1.4.0
  • Loading branch information
rafaelmaeuer authored Nov 30, 2022
2 parents eb1246d + c501035 commit 4a5e91f
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 483 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ingest-pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: yarn

- name: 🔑 Setup Google Cloud Auth
uses: google-github-actions/setup-gcloud@v0
uses: google-github-actions/setup-gcloud@v1
with:
service_account_key: ${{ secrets.GCP_GITHUB_SERVICE_ACCOUNT_KEY }}
export_default_credentials: true
Expand Down
44 changes: 22 additions & 22 deletions .github/workflows/ingest-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,20 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: "yarn"
cache-dependency-path: "**/yarn.lock"
cache: 'yarn'
cache-dependency-path: '**/yarn.lock'

- name: 📦 Install Dependencies
run: yarn

- name: 🔑 Setup Google Cloud Auth
uses: google-github-actions/setup-gcloud@v0
uses: google-github-actions/auth@v1
with:
service_account_key: ${{ secrets.GCP_GITHUB_SERVICE_ACCOUNT_KEY }}
export_default_credentials: true
credentials_json: ${{ secrets.GCP_GITHUB_SERVICE_ACCOUNT_KEY }}
create_credentials_file: true

- name: 🏗 Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1

- name: 📚 Lint Code
run: yarn ingest:lint
Expand All @@ -67,23 +70,24 @@ jobs:
runs-on: ubuntu-latest
needs: test
outputs:
BRANCH: ${{ steps.push.outputs.BRANCH }}
VERSION: ${{ steps.push.outputs.VERSION }}
steps:
- name: 👀 Checkout Code
uses: actions/checkout@v3

- name: 🔑 Setup Google Cloud Auth
uses: google-github-actions/setup-gcloud@v0
uses: google-github-actions/auth@v1
with:
service_account_key: ${{ secrets.GCP_GITHUB_SERVICE_ACCOUNT_KEY }}
export_default_credentials: true
credentials_json: ${{ secrets.GCP_GITHUB_SERVICE_ACCOUNT_KEY }}

- name: 🏗 Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1

- name: 🔑 Login to Registry
run: "gcloud auth configure-docker $REGISTRY_DOMAIN"
run: 'gcloud auth configure-docker $REGISTRY_DOMAIN'

- name: 🚧 Building docker image
run: "docker build ./ --file ./Dockerfile -t image"
run: 'docker build ./ --file ./Dockerfile -t image'

- name: 🔖 Get Package Version
id: package-version
Expand All @@ -109,33 +113,29 @@ jobs:
docker push $IMAGE_URI
# Update vars
echo "::set-output name=BRANCH::$BRANCH"
echo "::set-output name=VERSION::$VERSION"
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
# Print vars
echo "::warning docker::BRANCH $BRANCH"
echo "::warning docker::VERSION $VERSION"
echo "## Docker Version Tag" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "$VERSION" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
- name: 💬 Comment Branch and Version
- name: 💬 Comment Version
uses: peter-evans/create-or-update-comment@v2
if: github.event.pull_request.merged == true
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Docker container is ready!
BRANCH:
```
${{ steps.push.outputs.BRANCH }}
```
VERSION:
```
${{ steps.push.outputs.VERSION }}
```
- name: 👋 Logout
run: "docker logout"
run: 'docker logout'

deploy-A-dev-kubernetes:
if: github.event.pull_request.merged == true
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.4.0] - 2022-11-24

- chore: update express-openapi-validator to `v5`
- chore: update google-github-actions to `v1`
- chore: refactor env check and add google-auth
- chore: add env var checks to mocha-tests
- chore: migrate GitHub Actions from `::set-output` to new format
- chore: migrate to new `google-github-actions/auth` authentication
- fix: decouple logger init from config loading

## [1.3.9] - 2022-10-04

- chore: update dd-trace to `v3`
Expand Down
32 changes: 18 additions & 14 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,29 @@
const { version } = require('../package.json')
const coreIdPrefixes = require('./coreIdPrefixes.json')

// check existence of several process vars
if (!process.env.SERVICE_NAME) {
console.error('process.env.SERVICE_NAME not found')
process.exit(1)
} else if (!process.env.GCP_PROJECT_ID) {
console.error('process.env.GCP_PROJECT_ID not found')
process.exit(1)
} else if (!process.env.FIREBASE_API_KEY) {
console.error('process.env.FIREBASE_API_KEY not found')
process.exit(1)
} else if (!process.env.PUBSUB_SERVICE_ACCOUNT_EMAIL_INTERNAL) {
console.error('process.env.PUBSUB_SERVICE_ACCOUNT_EMAIL_INTERNAL not found')
process.exit(1)
}
// load winston logger
const logger = require('../src/utils/logger')

// read env vars
const stage = process.env.STAGE.toLowerCase()
const port = process.env.PORT || 8080

const exitWithError = (message) => {
logger.log({
level: 'error',
message,
source: 'config',
})
process.exit(1)
}

// check env vars
if (!process.env.SERVICE_NAME) exitWithError('SERVICE_NAME not found')
if (!process.env.GCP_PROJECT_ID) exitWithError('GCP_PROJECT_ID not found')
if (!process.env.FIREBASE_API_KEY) exitWithError('FIREBASE_API_KEY not found')
if (!process.env.GOOGLE_APPLICATION_CREDENTIALS) exitWithError('GOOGLE_APPLICATION_CREDENTIALS not found')
if (!process.env.PUBSUB_SERVICE_ACCOUNT_EMAIL_INTERNAL) exitWithError('PUBSUB_SERVICE_ACCOUNT_EMAIL_INTERNAL not found')

// set protocol, hostname and hostUrl
const protocol = stage === 'dev' ? 'http' : 'https'
const hostname = stage === 'dev' ? 'localhost' : `eventhub-ingest.ard.de`
Expand Down
2 changes: 1 addition & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"name": "European Union Public License 1.2",
"url": "https://spdx.org/licenses/EUPL-1.2.html"
},
"version": "1.3.9"
"version": "1.4.0"
},
"externalDocs": {
"description": "ARD-Eventhub Documentation",
Expand Down
2 changes: 1 addition & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ info:
license:
name: European Union Public License 1.2
url: "https://spdx.org/licenses/EUPL-1.2.html"
version: 1.3.9
version: 1.4.0
externalDocs:
description: ARD-Eventhub Documentation
url: "https://swrlab.github.io/ard-eventhub/"
Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ard-eventhub",
"version": "1.3.9",
"version": "1.4.0",
"description": "ARD system to distribute real-time (live) metadata for primarily radio broadcasts.",
"main": "./src/ingest/index.js",
"engines": {
Expand Down Expand Up @@ -30,36 +30,36 @@
"license": "EUPL-1.2",
"dependencies": {
"@google-cloud/datastore": "^7.0.0",
"@google-cloud/pubsub": "^3.2.0",
"@google-cloud/secret-manager": "^4.1.3",
"@google-cloud/pubsub": "^3.2.1",
"@google-cloud/secret-manager": "^4.1.4",
"@swrlab/utils": "^1.0.1",
"compression": "^1.7.4",
"dd-trace": "^3.3.1",
"dd-trace": "^3.8.0",
"dotenv": "^16.0.3",
"express": "4.18.1",
"express-openapi-validator": "^4.13.8",
"firebase-admin": "^11.0.1",
"google-auth-library": "^8.5.2",
"express": "4.18.2",
"express-openapi-validator": "^5.0.0",
"firebase-admin": "^11.3.0",
"google-auth-library": "^8.7.0",
"jsonwebtoken": "^8.5.1",
"moment": "^2.29.4",
"slug": "^8.2.2",
"swagger-ui-express": "^4.5.0",
"swagger-ui-express": "^4.6.0",
"uuid": "^9.0.0",
"winston": "^3.8.2"
},
"devDependencies": {
"@swrlab/eslint-plugin-swr": "^0.2.0",
"@swrlab/swr-prettier-config": "^0.2.0",
"chai": "^4.3.6",
"chai": "^4.3.7",
"chai-http": "^4.3.0",
"docsify-cli": "^4.4.4",
"eslint": "^8.24.0",
"eslint": "^8.28.0",
"eslint-plugin-chai-friendly": "^0.7.2",
"license-compliance": "^1.2.5",
"mocha": "^10.0.0",
"mocha": "^10.1.0",
"nodemon": "^2.0.20",
"prettier": "^2.7.1",
"typescript": "^4.8.4"
"prettier": "^2.8.0",
"typescript": "^4.9.3"
},
"resolutions": {
"ansi-regex": "^5.0.1",
Expand Down
35 changes: 21 additions & 14 deletions src/utils/logger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
// load node utils
const { createLogger, config, format, transports } = require('winston')

// load config
const serviceConfig = require('../../../config')
// get version
const { version } = require('../../../package.json')

// add formatters
// set error formatter
const convertError = format((event) => {
if (event?.error instanceof Error) {
event.error = {
Expand All @@ -23,26 +23,33 @@ const convertError = format((event) => {
return event
})

// set converter for globals
const convertGlobals = format((event) => {
event.serviceName = 'eventhub-ingest'
event.stage = process.env.STAGE
event.version = serviceConfig.version
event.version = version
event.nodeVersion = process.version
return event
})

// set format converters
let formatConfig = format.combine(convertError(), convertGlobals(), format.json())
if (process.env.DEBUG === 'true') {
formatConfig = format.combine(
convertError(),
convertGlobals(),
format.timestamp(),
format.json({ space: '\t' }),
format.colorize({ all: true, colors: { info: 'blue' } })
)
}

// initialize logger
const logger = createLogger({
level: 'info',
level: process.env.STAGE === 'dev' ? 'debug' : 'info',
levels: config.syslog.levels,
exitOnError: false,
format: serviceConfig.isDebug
? format.combine(
convertError(),
convertGlobals(),
format.timestamp(),
format.json({ space: '\t' }),
format.colorize({ all: true, colors: { info: 'blue' } })
)
: format.combine(convertError(), convertGlobals(), format.json()),
format: formatConfig,
transports: [new transports.Console()],
})

Expand Down
29 changes: 25 additions & 4 deletions test/ingest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
const chai = require('chai')
const moment = require('moment')
const chaiHttp = require('chai-http')

const server = require('../src/ingest/index')
const logger = require('../src/utils/logger')

// Init chai functions
const { expect } = chai
Expand All @@ -24,12 +26,31 @@ const should = chai.should()
// Use chaiHttp
chai.use(chaiHttp)

const exitWithError = (message) => {
logger.log({
level: 'error',
message,
source: 'config',
})
process.exit(1)
}

// check required env vars
if (!process.env.TEST_USER) exitWithError('TEST_USER not found')
if (!process.env.TEST_USER_PW) exitWithError('TEST_USER_PW not found')

// set test-user env vars
const testUser = process.env.TEST_USER
const testUserPass = process.env.TEST_USER_PW
const testUserReset = process.env.TEST_USER_RESET

// define general tests
function testResponse(res, status) {
expect(res).to.be.json
expect(res).to.have.status(status)
}

// check rejection of invalid token
function testAuth(res) {
expect(res).to.have.status(403)
}
Expand All @@ -55,8 +76,8 @@ function testAuthKeys(body) {
describe(`POST ${loginPath}`, () => {
it('swap login credentials for an id-token', (done) => {
const loginRequest = {
email: process.env.TEST_USER,
password: process.env.TEST_USER_PW,
email: testUser,
password: testUserPass,
}

chai.request(server)
Expand Down Expand Up @@ -97,11 +118,11 @@ describe(`POST ${refreshPath}`, () => {
// 🚨 firebase limit is 150 requests per day 🚨
const resetPath = '/auth/reset'

if (process.env.TEST_USER_RESET === true) {
if (testUserReset === true) {
describe(`POST ${resetPath}`, () => {
it('request password reset email', (done) => {
const resetRequest = {
email: process.env.TEST_USER,
email: testUser,
}

chai.request(server)
Expand Down
Loading

0 comments on commit 4a5e91f

Please sign in to comment.