Skip to content

Instantly share code, notes, and snippets.

View YannMjl's full-sized avatar
💭
Learning is experience; everything else is just information!

Yann Mulonda YannMjl

💭
Learning is experience; everything else is just information!
View GitHub Profile
@YannMjl
YannMjl / main.yml
Last active June 1, 2021 17:59
This is Github Action for nodejs express demo app
# This is a basic workflow to help you get started with Actions
name: CI-CD
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
@YannMjl
YannMjl / Dockerfile
Created June 1, 2021 16:08
this is Dockerfile for a demo Nodejs express app
FROM node
LABEL authors="Yann Mulonda"
# update dependencies and install curl
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create app directory
WORKDIR /app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# ---------------------------------------------------------------------------------*
# This will prevent your local modules and debug logs from being copied onto your
# Docker image and possibly overwriting modules installed within your image.
# ---------------------------------------------------------------------------------*
node_modules
npm-debug.log
# ignore .git and .cache folders
.git
.cache
# ignore all markdown files (md) beside all README*.md other than README-secret.md
// ****************************************************************
// We're testing our app using JEST library
// Jest is a library for testing JavaScript code. It's an open
// source project maintained by Facebook.
// Jest is a way for having access to test runner and assertion
// library for NodeJS applications.
// ****************************************************************
describe("Testing our nodeJS app", () => {
it("Testing using Github Actions", () => {
// exoecting 3 functions and receiving 3
// *******************************************************************
// "Routes" to forward the supported requests (and any information
// encoded in request URLs) to the appropriate controller functions.
// *******************************************************************
// import my GET API from the controller functions
import { home, getTodayDate, getMonthsName,getIPeople } from '../controller/controller.js';
// set up the routing
const routes = (app) => {
// home page
app.route('/')
<!DOCTYPE html>
<html>
<head>
<title>nodeJS demo</title>
<style>
body {background-image: url('https://mdbootstrap.com/img/Photos/Others/images/77.jpg')}
h1,h2 {color: white; font-weight: bold;}
p {color: white;}
</style>
</head>
@YannMjl
YannMjl / controller.js
Last active June 1, 2021 00:31
This is the controller.js for nodejs-app-demo article
// ****************************************************************
// Controller functions to get the requested data from the models,
// create an HTML page displaying the data, and return it to the
// user to view in the browser.
// ****************************************************************
import path from 'path';
const __dirname = path.resolve();
// show html page
export const home = (req, res) => {
//show this file when the "/" is requested
@YannMjl
YannMjl / app.js
Created May 31, 2021 23:36
This is the app.js for nodejs-app-demo article
// import Express and routes
import express from 'express';
import routes from './source/routes/route.js';
// constant variables
const app = express();
const PORT = 3000;
const HOST = '0.0.0.0';
// body parser setup for Express v4.16.0 and higher
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
FROM node
# update dependencies and install curl
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create app directory
WORKDIR /app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
@YannMjl
YannMjl / .gitlab-ci.yml
Created May 6, 2021 19:16
DevSecOps with Gitlab secure -- This file including security scans
variables:
VERSION: v2
MYNAME: Charlie
stages:
- npmtest
- sastscan
- dockerbuild
# test is the default Gitlad stage name when setting up SAST
- test
- runapp