Skip to content

Commit

Permalink
Start Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
giade committed Mar 13, 2024
1 parent ba7759c commit 9607605
Show file tree
Hide file tree
Showing 10,877 changed files with 1,191,145 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
62 changes: 62 additions & 0 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Deploy to Staging

on:
push:
branches: [ development ]

jobs:
deploy-staging:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/development'
steps:
- uses: satackey/[email protected]
# Ignore the failure of a step and avoid terminating the job.
continue-on-error: true

- name: Save my code in site directory
uses: actions/checkout@v3
with:
token: ${{ secrets.GIT_PAT }} #Your GitHub access token
ref: development

- name: Set my ssh key and ssh-agent
uses: webfactory/[email protected]
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: 18

- name: Install dependencies
run: yarn install
working-directory: src

# Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2

# install Docker and enable docker service
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Run test
run: docker-compose run addressbook npm test
working-directory: src

- name: Deploy Staging using ansible
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.STAGING_SERVER }}
username: ${{ secrets.STAGING_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /var/www/addressbook
git pull
docker-compose down
docker-compose up -d
Empty file added .gitignore
Empty file.
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Dockerfile

FROM registry.semaphoreci.com/node:18
RUN mkdir -p /opt/app
WORKDIR /opt/app
COPY src/package.json src/package-lock.json .
RUN npm install
COPY src/ .
EXPOSE 3000
CMD [ "npm", "start"]
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# docker-compose.yml

version: "3.9"
services:
postgres:
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- '5432:5432'

addressbook:
build:
context: .
dockerfile: ./Dockerfile
command: "npm start"
volumes:
- /opt/app/node_modules
- ./src:/opt/app
environment:
DB_SCHEMA: postgres
DB_USER: postgres
DB_PASSWORD: postgres
DB_HOST: postgres
depends_on:
- postgres
ports:
- '3000:3000'

volumes:
addressbook-db:
23 changes: 23 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var usersRouter = require('./routes/users');
var indexRouter = require('./routes/index');
// add the following line near the indexRouter
var personsRouter = require('./routes/persons');

var app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/persons', personsRouter);

module.exports = app;
4 changes: 4 additions & 0 deletions src/bin/migrate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// bin/migrate.js

var db = require('../database.js');
db.sequelize.sync();
86 changes: 86 additions & 0 deletions src/bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

const app = require('../app'); // Update the path based on your project structure
const debug = require('debug')('your-app-name:server');
const http = require('http');

/**
* Get port from environment and store in Express.
*/

const port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

const server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
const port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
const addr = server.address();
const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
debug('Listening on ' + bind);
}
28 changes: 28 additions & 0 deletions src/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// database.js

const Sequelize = require('sequelize');
const sequelize = new Sequelize(process.env.DB_SCHEMA || 'postgres',
process.env.DB_USER || 'postgres',
process.env.DB_PASSWORD || 'postgres',
{
host: process.env.DB_HOST || 'localhost',
port: process.env.DB_PORT || 5432,
dialect: 'postgres',
dialectOptions: {
ssl: process.env.DB_SSL == "true"
}
});
const Person = sequelize.define('Person', {
firstName: {
type: Sequelize.STRING,
allowNull: false
},
lastName: {
type: Sequelize.STRING,
allowNull: true
},
});
module.exports = {
sequelize: sequelize,
Person: Person
};
37 changes: 37 additions & 0 deletions src/database.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const db = require('./database');

beforeAll(async () => {
await db.sequelize.sync({ force: true });
});

test('create person', async () => {
expect.assertions(1);
const person = await db.Person.create({
id: 1,
firstName: 'Bobbie',
lastName: 'Draper'
});
expect(person.id).toEqual(1);
});

test('get person', async () => {
expect.assertions(2);
const person = await db.Person.findByPk(1);
expect(person.firstName).toEqual('Bobbie');
expect(person.lastName).toEqual('Draper');
});

test('delete person', async () => {
expect.assertions(1);
await db.Person.destroy({
where: {
id: 1
}
});
const person = await db.Person.findByPk(1);
expect(person).toBeNull();
});

afterAll(async () => {
await db.sequelize.close();
});
1 change: 1 addition & 0 deletions src/node_modules/.bin/blessed

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/browserslist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/create-jest

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/escodegen

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/esgenerate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/esparse

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/esvalidate

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/import-local-fixture

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/jest

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/jsesc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/json2yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/mkdirp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/needle

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/node-which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/parser

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/pm2

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/pm2-dev

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/pm2-docker

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/pm2-runtime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/resolve

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/systeminformation

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/update-browserslist-db

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/node_modules/.bin/yaml2json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9607605

Please sign in to comment.