Skip to content

Commit

Permalink
Added workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldlangeveld committed Dec 15, 2024
1 parent 38e5b43 commit c810b0c
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
npm-debug.log
.env
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build and Push Docker Image

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Check out the repository
uses: actions/checkout@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build the Docker image
run: |
docker build -t ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest .
- name: Push the Docker image
run: |
docker push ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:latest
2 changes: 1 addition & 1 deletion clientLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ const assetLoader = () => {
module.exports = {
clientLoader,
assetLoader
}
}
2 changes: 1 addition & 1 deletion db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ const knexfile = require('./knexfile')

const db = require('knex')(knexfile['development'])

module.exports = db;
module.exports = db;
12 changes: 8 additions & 4 deletions db/knexfile.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
const path = require('path');

// Define dbPath from an environment variable or default to 'db.sqlite3' in the current directory
const dbPath = process.env.DATABASE_PATH || path.join(__dirname, 'db.sqlite3');

/**
* @type { Object.<string, import("knex").Knex.Config> }
*/
module.exports = {
development: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, 'db.sqlite3')
filename: dbPath, // Use the dbPath variable here
},
migrations: {
tableName: 'knex_migrations'
tableName: 'knex_migrations',
},
useNullAsDefault: true,
}
useNullAsDefault: true, // Required for SQLite
},
};
19 changes: 19 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "3.8"

services:
app:
build:
context: .
ports:
- "3123:3123"
volumes:
- .:/usr/src/app
- sqlite-db:/usr/src/app/database
environment:
- NODE_ENV=production
- DATABASE_PATH=/usr/src/app/database/app.sqlite
command: ["node", "index.js"]
restart: unless-stopped

volumes:
sqlite-db:
20 changes: 20 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use the Node.js 16 image
FROM node:20-alpine

# Set the working directory inside the container
WORKDIR /usr/src/app

# Copy the package.json and package-lock.json
COPY package*.json ./

# Install dependencies
RUN yarn install

# Copy the entire app code into the container
COPY . .

# Expose the application port
EXPOSE 3123

# Set the default command to start the app
CMD ["node", "index.js"]
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const express = require('express');
const app = express();
const port = 3123;
const bodyparser = require('body-parser');
const path = require('path');
const routes = require('./routing/routes');
const {updateSolarData} = require('./services/sched/jobs');

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"license": "MIT",
"scripts": {
"dev": "npx nodemon index.js",
"setup": "concurrently \"cd ./db && npx knex migrate:latest\" \"cd ./client && yarn build\""
"setup": "concurrently \"cd ./db && npx knex migrate:latest\" \"cd ./client && yarn build\"",
"start": "node index.js"
},
"dependencies": {
"axios": "^0.27.2",
Expand Down
2 changes: 1 addition & 1 deletion routing/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ module.exports = function routes() {
router.get('/api/dailyCount', api.dailyCount.view);
router.get('/api/ping', api.ping.view);
return router;
};
};
1 change: 0 additions & 1 deletion services/tasks/testPower.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const db = require('../../db/index');
// const { getLoadsheddingStatus } = require('../eskom/loadSheddingStatus');
const e = require('express');


const testPower = async () => {

const status = await getGridStatus().then((res) => {
Expand Down

0 comments on commit c810b0c

Please sign in to comment.