Skip to content

Commit

Permalink
Update configuration of badges (#32)
Browse files Browse the repository at this point in the history
* Update configuration of badges

* Set up eslint correctly with typescript

* fix all eslint errors

* Update action dependencies

* Tweak elint setup

* Just run eslint

* eslint stuff again

* more eslint stuff

* update lint script

* cleanup

* Use npm

* update dockerfile

* Update tests

* Use specific mailslurp inbox

* Add missing env variables to example

* Start test environment

* use environmental variables

* use correct env

* tests envalid stuff

* import dotenv

* copy env file

* 🍕 spicy jalapeones

* env struggle

* env file action again

* cici

* add own reporter

* fix env var

* await on close worker

* jest force exit
  • Loading branch information
mpfeil authored Oct 11, 2023
1 parent 7f6d507 commit 95435dd
Show file tree
Hide file tree
Showing 22 changed files with 6,134 additions and 4,872 deletions.
14 changes: 12 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
*.log
.DS_Store
.env
.env.example
.env.*
/local-data
/dist
/payloads
docker-compose.yml
*.conf
*.conf
jest.config.ts
.eslintignore
.eslintrc.json
.babelrc
.dockerignore
.git
.github
.gitignore
.prettierignore
.prettierrc.json
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ BADGR_CLIENT_SECRET=

# The following values are just for testing
MAILSLURP_API_KEY=
MAILSLURP_INBOX_ID=
MAILSLURP_INBOX_EMAIL_ADDRESS=
BADGE_CLASS_ENTITY_ID=
ISSUER_ENTITY_ID=
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist
node_modules
.github
**/*.test.ts
jest.config.ts
4 changes: 0 additions & 4 deletions .eslintrc.js

This file was deleted.

13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["./tsconfig.json"]
},
"plugins": ["@typescript-eslint"]
}
26 changes: 11 additions & 15 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint
name: 🔬 Lint

on:
push:
Expand All @@ -9,26 +9,22 @@ on:

jobs:
run-linters:
name: Run linters
name: ⬣ ESLint
runs-on: ubuntu-latest

steps:
- name: Check out Git repository
uses: actions/checkout@v2
- name: ⬇️ Check out Git repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v1
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20
cache: npm
cache-dependency-path: ./package.json

# ESLint and Prettier must be in `package.json`
- name: Install Node.js dependencies
- name: 💿 Install dependencies
run: npm install

- name: Run linters
uses: wearerequired/lint-action@v1
with:
github_token: ${{ secrets.github_token }}
# Enable linters
eslint: true
prettier: true
- name: 🔬 Run linters
run: npm run lint
18 changes: 9 additions & 9 deletions .github/workflows/registry-build-publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and publish to Github Container Registry
name: 🏗️ Build and publish to Github Container Registry

on:
push:
Expand All @@ -20,27 +20,27 @@ jobs:
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: ⬇️ Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
- name: 🔓 Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
- name: ℹ️ Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=auto
prefix=
suffix=
- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
- name: 🐳 Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/registry-pr-purge.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Purge Pull Request Image
name: 🗑️ Purge Pull Request Image

# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#registry_package
# Purge Pull Request Image
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/registry-purge.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Purge untagged images
name: 🗑️ Purge untagged images

# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#registry_package
# Run cleanup job if a new package was published or updated
Expand Down
50 changes: 43 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Jest Test
name: 🃏 Jest Test

on:
push:
Expand All @@ -8,11 +8,47 @@ on:
- main

jobs:
build:
test:
name:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn
- name: Run tests
run: yarn test
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
cache: npm
cache-dependency-path: ./package.json
node-version: 20

- name: 💿 Install dependencies
run: npm install

- name: 🐳 Docker compose
run: docker compose up -d && sleep 10

- name: 🏄 Copy test env vars
uses: SpicyPizza/create-envfile@v2.0
with:
envkey_REDIS_HOST: ${{ vars.REDIS_HOST }}
envkey_REDIS_PORT: ${{ vars.REDIS_PORT }}
envkey_REDIS_USERNAME: ${{ secrets.REDIS_USERNAME }}
envkey_REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD}}
envkey_REDIS_DB: ${{ vars.REDIS_DB }}
envkey_BULLMQ_QUEUE_NAME: ${{ vars.BULLMQ_QUEUE_NAME }}
envkey_BADGR_URL: ${{ vars.BADGR_URL }}
envkey_BADGR_ISSUER_ID: ${{ secrets.BADGR_ISSUER_ID }}
envkey_BADGR_USERNAME: ${{ secrets.BADGR_USERNAME }}
envkey_BADGR_PASSWORD: ${{ secrets.BADGR_PASSWORD}}
envkey_BADGR_CLIENT_ID: ${{ secrets.BADGR_CLIENT_ID}}
envkey_BADGR_CLIENT_SECRET: ${{secrets.BADGR_CLIENT_SECRET }}
envkey_BADGE_MAPPINGS: ${{ secrets.BADGE_MAPPINGS }}
envkey_MAILSLURP_API_KEY: ${{ secrets.MAILSLURP_API_KEY }}
envkey_MAILSLURP_INBOX_ID: ${{ secrets.MAILSLURP_INBOX_ID }}
envkey_MAILSLURP_INBOX_EMAIL_ADDRESS: ${{ secrets.MAILSLURP_INBOX_EMAIL_ADDRESS }}
envkey_BADGE_CLASS_ENTITY_ID: ${{ secrets.BADGE_CLASS_ENTITY_ID }}
envkey_ISSUER_ENTITY_ID: ${{ secrets.ISSUER_ENTITY_ID }}

- name: 🔬 Run tests
run: npm run test:ci
37 changes: 19 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
# Based on best pratices provided by Snyk.io
# https://snyk.io/blog/10-best-practices-to-containerize-nodejs-web-applications-with-docker/

# base node image
FROM node:18-bullseye-slim as base
# --------------> The build image
FROM node:20.8.0-bullseye-slim AS base
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init

# set for base and all layer that inherit from it
# ENV NODE_ENV production

# Install all noe_modules, including dev dependencies
# Install all node_modules, including dev dependencies
FROM base as deps

WORKDIR /app

ADD package.json yarn.lock ./
RUN yarn install
COPY package*.json /app
RUN npm ci

# Build the app
FROM base as build

WORKDIR /app

COPY --from=deps /app/node_modules /app/node_modules
ADD . .
RUN yarn build
COPY . .
RUN npm run build

# Setup production node_modules
FROM base as production-deps

WORKDIR /app

COPY --from=deps /app/node_modules /app/node_modules
ADD package.json yarn.lock ./
RUN yarn install --production
ADD package*.json ./
RUN npm prune --omit=dev

# Finally, build the production image with minimal footprint
# --------------> The production image
FROM base

WORKDIR /app
ENV NODE_ENV production
COPY --from=base /usr/bin/dumb-init /usr/bin/dumb-init

COPY --from=production-deps /app/node_modules /app/node_modules
USER node

COPY --from=build /app/dist /app/dist
ADD . .
WORKDIR /app
COPY --chown=node:node --from=production-deps /app/node_modules /app/node_modules
COPY --chown=node:node --from=build /app/dist /app/dist
COPY --chown=node:node . .

CMD ["node", "dist/index.js"]
CMD ["dumb-init", "node", "dist/index.js"]
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Config } from "@jest/types";
const config: Config.InitialOptions = {
preset: "ts-jest",
testEnvironment: "node",
setupFiles: ["dotenv/config"],
};

export default config;
4 changes: 2 additions & 2 deletions local-redis-stack.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ appendonly yes

################################## SECURITY ###################################

user queue on +@all -@dangerous +INFO ~bull:mails:* >somepassword
user worker on +@all -@dangerous +INFO +CLIENT ~bull:mails:* >somepassword
user queue on +@all -@dangerous +INFO ~bull:badgr:* >somepassword
user worker on +@all -@dangerous +INFO +CLIENT ~bull:badgr:* >somepassword

requirepass super-secret
Loading

0 comments on commit 95435dd

Please sign in to comment.