Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
60ff88e
Move things around and adopt new styles for both Node & Docker develo…
shuguet Mar 19, 2022
6281181
Fix scripts/dev.sh to allow faste debugging
shuguet Mar 19, 2022
32ac757
Ignore VSCode stuff
shuguet Mar 19, 2022
49f49a1
Working again
shuguet Mar 19, 2022
c33f0a5
Migrate from Jade to PUG3
shuguet Mar 19, 2022
4221b46
Cleanup README & Dockerfile
shuguet Mar 19, 2022
216233b
GitHub Actions: Create docker-image.yml
shuguet Mar 19, 2022
c00c44c
GitHub Actions: Add CodeQL Analysis
shuguet Mar 19, 2022
72781bc
Create SECURITY.md
shuguet Mar 19, 2022
5aa9b4a
Update .dockerignore
shuguet Mar 19, 2022
9585102
Merge pull request #1 from shuguet/refactor-and-upgrade-to-latest-npm
shuguet Mar 19, 2022
97d680d
Fix service backend name if running inside Kubernetes
shuguet Mar 20, 2022
10599c6
Updating CI/CD pipeline
shuguet Mar 26, 2022
52c85de
Bump minimist from 1.2.5 to 1.2.6
dependabot[bot] Mar 26, 2022
931246a
Merge pull request #2 from shuguet/dependabot/npm_and_yarn/minimist-1…
shuguet Mar 26, 2022
69043bc
Fix branch trigger name
shuguet Mar 26, 2022
6a4f7ea
Merge branch 'master' of github.com:shuguet/pacman
shuguet Mar 26, 2022
f048bf2
Initial chart version
shuguet Mar 26, 2022
76ab09d
Place chart in the directory expected by chart-releaser-action
shuguet Mar 26, 2022
40d1ed4
Bump chart version number & re-do Image tagging CI action
shuguet Mar 26, 2022
f8f7aba
cleanup
shuguet Mar 26, 2022
c39ec57
Fix 'latest' tagging for push on default branch
shuguet Mar 26, 2022
7063ab3
Merge pull request #3 from shuguet/docker-tagging-fix
shuguet Mar 26, 2022
5a73fb6
Rev up chart version number
shuguet Mar 26, 2022
f86c481
Merge pull request #4 from shuguet/rev-up-chart
shuguet Mar 26, 2022
d19c8bd
Update chart README
shuguet Mar 26, 2022
e053fb6
Merge branch 'master' of github.com:shuguet/pacman
shuguet Mar 26, 2022
1ae45f7
Fix icon in chart
shuguet Mar 26, 2022
3e0e746
Fix install instructions in chart
shuguet Mar 26, 2022
fa219cd
Update docs, supporting build scripts & Chart README
shuguet Mar 26, 2022
84d0b68
Refactor pacman
shuguet Mar 26, 2022
70b4850
Fix README
shuguet Mar 28, 2022
52ec4c5
use Alpine-based Node image
shuguet Apr 10, 2022
f2fbf9c
Update Chart & GH Actions to reflect renaming branch master to main
shuguet Apr 10, 2022
1951a6e
Bump http-cache-semantics from 4.1.0 to 4.1.1
dependabot[bot] Feb 4, 2023
ca64957
Remove pod security policy
michaelcourcy Feb 10, 2023
a20a173
Merge pull request #5 from shuguet/dependabot/npm_and_yarn/http-cache…
shuguet Feb 10, 2023
2e3abb8
Bump got and nodemon
dependabot[bot] Feb 10, 2023
7329ce0
Merge pull request #6 from michaelcourcy/main
shuguet Feb 10, 2023
52c0517
Merge pull request #7 from shuguet/dependabot/npm_and_yarn/got-and-no…
shuguet Feb 10, 2023
e1074f9
Releaser expect dependency to be installed first
michaelcourcy Feb 10, 2023
684ba20
Merge pull request #8 from shuguet/michaelcourcy-patch-1
shuguet Feb 10, 2023
7aeca4b
Change release number
michaelcourcy Feb 10, 2023
17d6414
Merge pull request #9 from shuguet/michaelcourcy-patch-1
shuguet Feb 10, 2023
f7ef98d
security fix on mgongo node client
michaelcourcy Sep 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
.dockerignore
Dockerfile
.github
.devcontainer
.git
.gitignore
README.md
SECURITY.md
scripts
charts
node_modules
npm-debug.log
70 changes: 70 additions & 0 deletions .github/workflows/codeql-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '0 2 * * 5'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
54 changes: 54 additions & 0 deletions .github/workflows/docker-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Docker Image CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: "0 2 * * 1-5"

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# TODO: Check support for multi-platform then enable build for all supported ones
# -
# name: Set up QEMU
# uses: docker/setup-qemu-action@v1
# -
# name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1
-
name: Log in to GitHub Container registry (GHCR)
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=sha
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
-
name: Build and push Docker image
uses: docker/build-push-action@v2
with:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
34 changes: 34 additions & 0 deletions .github/workflows/release-helm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release Charts

on:
push:
branches:
- main

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"

- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.7.1

- name: Add helm repo dependencies
run: |
helm repo add bitnami https://charts.bitnami.com/bitnami

- name: Run chart-releaser
uses: helm/chart-releaser-action@v1.3.0
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
# VSCode stuff
.devcontainer
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:current-alpine

LABEL org.opencontainers.image.authors="sylvain@huguet.me"

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install app dependencies
COPY package*.json ./

# Install app dependencies
# Development
RUN npm install
# Production
RUN npm ci --only=production

# Bundle app source
# Refer to .dockerignore to exclude content as needed
COPY . .

# Expose port 8080
EXPOSE 8080

# Run container
CMD [ "npm", "start" ]
63 changes: 38 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,71 @@
# pacman
Pac-Man
# Pac-Man
Pac-Man Demo App for Kubernetes

## Install dependencies
![GitHub](https://img.shields.io/github/license/shuguet/pacman)
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/pacman)](https://artifacthub.io/packages/search?repo=pacman)
![Build & Publish Container](https://github.com/shuguet/pacman/actions/workflows/docker-image.yaml/badge.svg)

## Installation instructions:
[Using Helm](https://artifacthub.io/packages/helm/pacman/pacman)

## Development instructions

#### Getting started

Build the image locally once, to check everything is working fine
```
npm install
./scripts/build.sh
```

## Getting started

Once inside the build environment, you can use
```
npm run start
npm install
```
to update/install newer versions of the Node.js packages used by the app.

## Development
If you don't see any error, you should proceed with starting the development environment
```
./scripts/dev.sh
```

You should be inside one container, on the same network as a running MongoDB database server.
```
npm run dev
```

## Create Application Container Image
You should see your Node.js server logs, keep the server running.
Open a new browser windows, navigate to `http://localhost:8000/`, you should see the Pac-Man game.

## Create Application Artifacts

### Docker Container Image

The [Dockerfile](docker/Dockerfile) performs the following steps:
The [Dockerfile](Dockerfile) performs the following steps:

1. It is based on Node.js LTS Version 6 (Boron).
1. It then clones the Pac-Man game into the configured application directory.
1. It is based on the latest Node.js.
1. It then ADD the Pac-Man game into the configured application directory.
1. Exposes port 8080 for the web server.
1. Starts the Node.js application using `npm start`.

To build the image run:
To build the image in preparation for hosting it to your own repo, run:

```
cd docker
docker build -t <registry>/<user>/pacman-nodejs-app .
docker build -t <registry>/<user>/pacman .
```

You can test the image by running:

```
docker run -p 8000:8080 <registry>/<user>/pacman-nodejs-app
docker run -p 8000:8080 <registry>/<user>/pacman
```
Note: You will need a working MongoDB backend. Look at [scripts/dev.sh] to understand how you can setup a local one on your machine using an insecure password, for development purposes only.

And going to `http://localhost:8000/` to see if you get the Pac-Man game.

Once you're satisfied you can push the image to the container registry.
Once you're satisfied you can push the image to your container registry.

```
docker push <registry>/<user>/pacman-nodejs-app
docker push <registry>/<user>/pacman
```

### Building using an s2i image

```
s2i build . centos/nodejs-6-centos7 pacman
```
#### Helm Chart
Explore [charts/pacman](charts/pacman) to understand how the chart is built.
To host your own, you will need to setup a [Helm Repository](https://helm.sh/docs/topics/chart_repository/)
5 changes: 5 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Security Policy

## Reporting a Vulnerability

If you find a vulnerability, please reach out directly over email <sylvain@huguet.me>
59 changes: 31 additions & 28 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
'use strict';

var express = require('express');
var path = require('path');
var Database = require('./lib/database');
var assert = require('assert');
import express from 'express';
import path from 'path';
import {fileURLToPath} from 'url';
import Database from './lib/database.js';

// Constants
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Routes
var highscores = require('./routes/highscores');
var user = require('./routes/user');
var loc = require('./routes/location');
import highscores from './routes/highscores.js';
import user from './routes/user.js';
import loc from './routes/location.js';

// App
var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// app.set('view engine', 'jade'); // "jade": "^0.29.0",
app.set('view engine', 'pug');

// Handle root web server's public directory
app.use('/', express.static(path.join(__dirname, 'public')));
Expand All @@ -28,32 +31,32 @@ app.use('/location', loc);

// Catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
var err = new Error('Not Found');
err.status = 404;
next(err);
});

// Error Handler
app.use(function(err, req, res, next) {
if (res.headersSent) {
return next(err)
}
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
if (res.headersSent) {
return next(err)
}
// set locals, only providing error in development
res.locals.title = 'Pac-Man Error';
res.locals.message = `Error message: ${err.message}`;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});

Database.connect(app, function(err) {
if (err) {
console.log('Failed to connect to database server');
} else {
console.log('Connected to database server successfully');
}

if (err) {
console.log('Failed to connect to database server');
} else {
console.log('Connected to database server successfully');
}
});

module.exports = app;
export default app;
Loading