-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cc5e199
Showing
269 changed files
with
40,348 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
DATABASE_URL="postgresql://postgres:votingsecret@localhost:5432/votingdb" | ||
MOCKING=false | ||
DEVELOPMENT=true | ||
AUTH0_DOMAIN=dev-4bxg75mo.eu.auth0.com | ||
AUTH0_AUDIENCE=https://stemmesystem/api | ||
NODE_ENV='development' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', // Specifies the ESLint parser | ||
parserOptions: { | ||
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features | ||
sourceType: 'module', // Allows for the use of imports | ||
}, | ||
settings: {}, | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from @typescript-eslint/eslint-plugin | ||
'prettier', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array. | ||
], | ||
plugins: ['graphql', 'prettier'], | ||
rules: { | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
}, | ||
ignorePatterns: ['**/__generated__/*'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Lint | ||
on: push | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
name: Run linters | ||
steps: | ||
- name: Check out Git repository | ||
uses: actions/checkout@v2 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: '**/node_modules' | ||
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14 | ||
|
||
- name: Install Node.js dependencies | ||
run: yarn | ||
|
||
- name: Run linters | ||
uses: wearerequired/lint-action@v1 | ||
with: | ||
eslint: true | ||
prettier: true | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
test: | ||
runs-on: ubuntu-latest | ||
services: | ||
# Label used to access the service container | ||
postgres: | ||
# Docker Hub image | ||
image: postgres:12 | ||
# Provide the password for postgres | ||
env: | ||
POSTGRES_PASSWORD: votingsecret | ||
POSTGRES_DB: votingdb | ||
# Set health checks to wait until postgres has started | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
ports: | ||
- 5432:5432 | ||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v2 | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14 | ||
- name: Install Node.js dependencies | ||
run: yarn | ||
- name: Run tests | ||
run: yarn test | ||
env: | ||
DATABASE_URL: 'postgresql://postgres:votingsecret@localhost:5432/votingdb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Continuous Deployment | ||
|
||
on: | ||
workflow_dispatch: | ||
release: | ||
types: [published, edited] | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
deploy: | ||
if: '!github.event.release.prerelease' | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
# Setup cache and Docker action | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
# Build docker image | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- name: Cache Docker layers | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
# Login | ||
- name: Login to Docker registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.CR_PAT }} | ||
|
||
# Build and push docker container | ||
- name: Build and push Image to Github Container Registry | ||
id: docker_build | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: true | ||
tags: ${{ steps.docker_meta.outputs.tags }},ghcr.io/organisasjonskollegiet/voting-backend:${{ github.sha }} # Add the SHA as a tag | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache | ||
build-args: | | ||
${{ secrets.BUILD_ARGS }} | ||
- name: Deploy to Azure Web App | ||
uses: azure/webapps-deploy@v2 | ||
with: | ||
app-name: vaas | ||
images: 'ghcr.io/organisasjonskollegiet/voting-backend:${{ github.sha }}' | ||
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Migrate database | ||
on: | ||
workflow_run: | ||
workflows: ['Continuous Deployment'] | ||
types: | ||
- completed | ||
workflow_dispatch: | ||
release: | ||
types: [published, edited] | ||
jobs: | ||
migrate: | ||
runs-on: ubuntu-latest | ||
environment: Migration | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/cache@v2 | ||
with: | ||
path: '**/node_modules' | ||
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14 | ||
- name: Install Node.js dependencies | ||
run: yarn | ||
|
||
- name: Run migrations | ||
run: yarn migrate:db | ||
env: | ||
DATABASE_URL: ${{ secrets.DATABASE_URL }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Inspect GraphQL | ||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
inspect_schema: | ||
name: Inspect GraphQL schema | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out Git repository | ||
uses: actions/checkout@v2 | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14 | ||
- name: Report GraphQL Schema | ||
uses: kamilkisiela/[email protected] | ||
with: | ||
schema: 'master:src/__generated__/schema.graphql' | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
fail-on-breaking: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
.env | ||
package-lock.json | ||
yarn-error.log | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
__generated__ | ||
codegen.yml | ||
package.json | ||
tsconfig.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
semi: true, | ||
singleQuote: true, | ||
printWidth: 120, | ||
tabWidth: 4, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ | ||
// Place your voting-backend workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and | ||
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope | ||
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is | ||
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | ||
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. | ||
// Placeholders with the same ids are connected. | ||
// Example: | ||
"Nexus-Resolve": { | ||
"prefix": ["resolve"], | ||
"body": ["resolve: async (_, __, ctx) => {", "\treturn null", "}"], | ||
"description": "Nexus graphql resolve" | ||
}, | ||
"NexusMutation": { | ||
"prefix": ["mutation"], | ||
"body": [ | ||
"export const $1 = mutationField('$2', {", | ||
"\ttype: $3,", | ||
"\tdescription: '',", | ||
"\targs: { ${4:arg_name} : ${5:arg_type}},", | ||
"\tresolve: async (_, {$4}, ctx) => {", | ||
"\t\t${0:return null}", | ||
"\t}", | ||
"})" | ||
] | ||
}, | ||
"NexusMutationWithoutArgs": { | ||
"prefix": ["mutation-no-args"], | ||
"body": [ | ||
"export const $1 = mutationField('$2', {", | ||
"\ttype: $3,", | ||
"\tdescription: '',", | ||
"\tresolve: async (_, __, ctx) => {", | ||
"\t\t${0:return null}", | ||
"\t}", | ||
"})" | ||
] | ||
}, | ||
"NexusQuery": { | ||
"prefix": ["query"], | ||
"body": [ | ||
"export const $1 = queryField('$2', {", | ||
"\ttype: $3,", | ||
"\tdescription: '',", | ||
"\targs: { ${4:arg_name} : ${5:arg_type}},", | ||
"\tresolve: async (_, {$4}, ctx) => {", | ||
"\t\t${0:return null}", | ||
"\t}", | ||
"})" | ||
] | ||
}, | ||
"NexusQueryWithoutArgs": { | ||
"prefix": ["query-no-args"], | ||
"body": [ | ||
"export const $1 = queryField('$2', {", | ||
"\ttype: $3,", | ||
"\tdescription: '',", | ||
"\tresolve: async (_, __, ctx) => {", | ||
"\t\t${0:return null}", | ||
"\t}", | ||
"})" | ||
] | ||
}, | ||
"NexusObjectTypes": { | ||
"prefix": ["objectType"], | ||
"body": [ | ||
"export const $1 = objectType({", | ||
"\tname: '$2',", | ||
"\tdescription: 'Another object',", | ||
"\tdefinition(t) {", | ||
"\t\t $0", | ||
"\t}", | ||
"})" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
## this is the stage one , also know as the build step | ||
|
||
FROM node:14-alpine | ||
WORKDIR /app | ||
COPY package.json ./ | ||
COPY yarn.lock ./ | ||
# This will cache | ||
RUN yarn | ||
COPY ./prisma/schema.prisma ./ | ||
RUN yarn generate | ||
COPY . . | ||
RUN yarn run build | ||
|
||
## this is stage two , where the app actually runs | ||
|
||
FROM node:14-alpine | ||
|
||
WORKDIR /app | ||
COPY package.json ./ | ||
COPY yarn.lock ./ | ||
COPY ./prisma/schema.prisma ./ | ||
RUN yarn --only=production | ||
COPY --from=0 /app/dist ./dist | ||
EXPOSE 3000 | ||
CMD yarn start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Starting | ||
|
||
To quickly start the server in mockmode run: | ||
|
||
``` | ||
docker run -e MOCKING=true -p 4000:4000 voting-backend | ||
``` | ||
|
||
This is a version of the API which uses `casual` for mocking. The data wont actually come from a database, but its nice for frontend developers to chill | ||
|
||
To run up a postgres database in a docker container which can be used locally and is compatible with .env.local | ||
|
||
``` | ||
docker run --name votingdb -p 5432:5432 -e POSTGRES_PASSWORD=votingsecret -e POSTGRES_DB=votingdb -d postgres | ||
``` | ||
|
||
# Relevant scripts | ||
|
||
### `yarn generate` | ||
|
||
After making updates to the prisma schema, running this command will generate a migration. | ||
|
||
### `npx migrate dev` | ||
|
||
Migrate new updates of the prisma schema to the local database. | ||
|
||
### `npx prisma studio` | ||
|
||
Lets you see and edit the content of the database. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
version: '3.8' | ||
|
||
services: | ||
votingdb: | ||
image: postgres | ||
container_name: votingdb | ||
ports: | ||
- "5432:5432" | ||
environment: | ||
POSTGRES_PASSWORD: votingsecret | ||
POSTGRES_DB: votingdb | ||
volumes: | ||
- votingdb_data:/var/lib/postgresql/data | ||
restart: always | ||
|
||
redis: | ||
image: redis | ||
container_name: redis | ||
ports: | ||
- "6379:6379" # Redis default port is 6379, mapped to 6380 on the host | ||
environment: | ||
REDIS_PASSWORD: redissecret # Set the Redis password here | ||
volumes: | ||
- redis_data:/data | ||
command: ["redis-server", "--requirepass", "redissecret"] # Ensure Redis requires a password | ||
restart: always | ||
web: | ||
build: | ||
context: . | ||
ports: | ||
- "80:80" | ||
volumes: | ||
- ./voting-app:/app | ||
restart: always | ||
|
||
volumes: | ||
votingdb_data: | ||
redis_data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testTimeout: 10000, | ||
}; |
Oops, something went wrong.