Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Keskimaki committed Aug 25, 2023
0 parents commit 772e1ed
Show file tree
Hide file tree
Showing 61 changed files with 11,259 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/production.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Deploy to production

on:
release:
types: [published]

jobs:
test:
uses: ./.github/workflows/test.yaml

build-and-push:
runs-on: ubuntu-latest
needs: test

steps:
- uses: actions/checkout@v3

- name: Build image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: openid-mongo-example
tags: production ${{ github.sha }}
containerfiles: |
./Containerfile
- name: Push to quay.io
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: quay.io/toska
username: toska+github
password: ${{ secrets.QUAY_IO_TOKEN }}
38 changes: 38 additions & 0 deletions .github/workflows/staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Deploy to staging

on:
push:
branches:
- main

jobs:
test:
uses: ./.github/workflows/test.yaml

build-and-push:
runs-on: ubuntu-latest
needs: test

steps:
- uses: actions/checkout@v3

- name: Build image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
image: openid-mongo-example
tags: staging ${{ github.sha }}
containerfiles: |
./Containerfile
build-args: |
BASE_PATH=/example
STAGING=true
- name: Push to quay.io
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: quay.io/toska
username: toska+github
password: ${{ secrets.QUAY_IO_TOKEN }}
37 changes: 37 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: E2E Tests

on: [workflow_call]

jobs:
eslint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Build project for eslint
run: npm install

- name: Run eslint
run: npm run lint

cypress:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Prepare test data and start the application
run: docker compose -f compose.ci.yaml up -d

- name: Cypress run
uses: cypress-io/github-action@v5
with:
browser: chrome
install-command: npm i

- name: Upload video
uses: actions/upload-artifact@v3
if: failure()
with:
path: /home/runner/work/openid-mongo-example/openid-mongo-example/cypress/videos/*
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
debug.log
node_modules
dist
.vscode
.env
videos
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
24 changes: 24 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM registry.access.redhat.com/ubi9/nodejs-18-minimal

ENV TZ="Europe/Helsinki"

WORKDIR /opt/app-root/src

ARG BASE_PATH
ENV BASE_PATH=$BASE_PATH

ARG STAGING
ENV STAGING=$STAGING

ARG E2E
ENV E2E=$E2E

COPY package* ./
RUN npm ci --omit-dev --ignore-scripts
COPY . .

RUN npm run build

EXPOSE 8000

CMD ["npm", "run", "prod"]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# OpenID Mongo Example

Example TypeScript setup for Software Engineering projects using OpenID Connect and MongoDB

## Development

- Install npm, docker and docker compose
- Clone the repository
- Run `npm i` and `npm start` to setup and start the development environment
22 changes: 22 additions & 0 deletions compose.ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
app:
build:
context: ./
dockerfile: Containerfile
args:
- E2E=true
image: test
environment:
- DATABASE_URL=mongodb://root:root@db/admin
ports:
- 8000:8000
container_name: test

db:
image: docker.io/mongo:7.0.0
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=root
ports:
- 27017:27017
container_name: test_db
28 changes: 28 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
app:
build:
context: ./
dockerfile: dev.Containerfile
image: dev
environment:
- DATABASE_URL=mongodb://root:root@db/admin
volumes:
- ./:/opt/app-root/src
ports:
- 3000:3000
- 8000:8000
container_name: dev

db:
image: docker.io/mongo:7.0.0
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=root
ports:
- 27017:27017
volumes:
- mongo_data:/data/db
container_name: dev_db

volumes:
mongo_data:
9 changes: 9 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
setupNodeEvents(_on, _config) {
// implement node event listeners here
},
},
})
11 changes: 11 additions & 0 deletions cypress/e2e/example.spec.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { baseUrl } from '../support/e2e'

describe('Example', () => {
beforeEach(() => {
cy.visit(baseUrl)
})

it('loads the main page', () => {
cy.contains('Esimerkkisovellus')
})
})
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
22 changes: 22 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

export const baseUrl = 'localhost:8000'

// Alternatively you can use CommonJS syntax:
// require('./commands')
12 changes: 12 additions & 0 deletions dev.Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM docker.io/node:18-alpine

ENV TZ="Europe/Helsinki"

WORKDIR /opt/app-root/src

COPY package* ./
RUN npm i

EXPOSE 3000

CMD ["npm", "run", "dev"]
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/png" href="/hy_favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OpenID Mongo Example</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/client/index.tsx"></script>
</body>
</html>
Loading

0 comments on commit 772e1ed

Please sign in to comment.