Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance/feature docker deploy #1011

Merged
merged 51 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
9505223
`update` logs for `PROD` server
migbash Jan 16, 2023
077b120
`update` for `Makefile`
migbash Jan 16, 2023
cf615e5
`update` for `.dockerignore`
migbash Jan 16, 2023
3aa29dd
`setup` of `Docker` development env
migbash Jan 16, 2023
034611c
`update` for `package.json` with `scripts:`
migbash Jan 16, 2023
e351418
`.gitignore` update
migbash Jan 16, 2023
a54cf44
`update` for `Docker` in `PROD` deployment
migbash Jan 16, 2023
843693d
`update` Makefile
migbash Jan 16, 2023
6bcb364
`update` for `README.md`
migbash Jan 16, 2023
3bd9336
`update` express server for `https`
migbash Jan 17, 2023
1054a51
add `new` deploy script with `Github Actions`
migbash Jan 17, 2023
f006710
`update` github actions test
migbash Jan 17, 2023
8e00ee2
`revert` for `http` only support
migbash Jan 17, 2023
36d4a25
`update` for `Makefile`
migbash Jan 17, 2023
c74a934
`update` for `deploy.yml`
migbash Jan 17, 2023
112e6fa
`revert` for `http` only support
migbash Jan 17, 2023
f721044
`add` for `https` deploy
migbash Jan 17, 2023
0e77f63
`update` - `Makefile`
migbash Jan 17, 2023
875d568
`update` - `my-server.js`
migbash Jan 17, 2023
fa930e3
issue `990`
migbash Jan 19, 2023
a2c55e9
issue `990` - `V1`
migbash Jan 19, 2023
1ad9c5f
issue #949
migbash Jan 19, 2023
5fcf56c
`update` packages
migbash Jan 24, 2023
46997a5
`update` for `github/actions`
migbash Jan 24, 2023
3da4ddb
issue #986
migbash Jan 24, 2023
0f27027
`logs` update
migbash Jan 24, 2023
f2da8f8
`update` for `settings.json`
migbash Jan 24, 2023
db11ce8
`update` issue #986
migbash Jan 24, 2023
bc96c2a
`update` for `mobile` view `auth`
migbash Jan 24, 2023
a88109d
`revert` express for `heroku`
migbash Jan 24, 2023
fcb6683
`revert` express for `heroku`
migbash Jan 24, 2023
6c216e8
`revert` express for `heroku`
migbash Jan 24, 2023
6adfd3c
`revert` for `DEV` test `heroku`
migbash Jan 24, 2023
d78d3a4
`revert` for `DEV` test `heroku`
migbash Jan 24, 2023
425ebc6
`revert` for `DEV` test `heroku`
migbash Jan 24, 2023
15209d3
`add` back `AuthWidget`
migbash Jan 24, 2023
f47bed7
issue #1004
migbash Jan 24, 2023
9e9e6e7
issue #1004
migbash Jan 24, 2023
651875d
issue #1004 `checkout`
migbash Jan 25, 2023
6d754bc
`update` example widget
migbash Jan 25, 2023
1ba4df6
issue #1004
migbash Jan 25, 2023
9bd80e9
issue #1004 `dark-mode` hovers
migbash Jan 25, 2023
cca20ec
issue #1004 `🐞 debug`
migbash Jan 25, 2023
5d7ecda
issue #1004 `🐞 debug`
migbash Jan 25, 2023
f75b50d
issue #1004
migbash Jan 25, 2023
168c129
issue #1004 `🐞 debug update`
migbash Jan 25, 2023
08be06a
`revert` to `PROD` of `express-server`
migbash Jan 25, 2023
0431735
`deepsource` JS-0239
migbash Jan 25, 2023
0d20204
`deepsource` JS-0239
migbash Jan 25, 2023
205585c
`deepsource` JS-0242
migbash Jan 25, 2023
15e3d26
`deepsource` JS-T1001
migbash Jan 25, 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
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
node_modules/
npm-debug.log
36 changes: 36 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# ....................................
# ... GITHUB ACIONS CI/CD WORKFLOW ...
# ....................................
# DESCRIPTION
# ....................................
# This Github Action is responsible with the
# auto-deployment of the main (branch) to the
# location of the server
# ....................................

name: 🚀 Deployment
# [ℹ] when to trigger this project
on:
push:
branches: [main]
# [ℹ] JOBS TO DO WITH GITHUB WORFLOWS;
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: executing remote ssh commands using password
uses: appleboy/[email protected]
# [ℹ] declaring ENV variables to be used in the project-CI/CD
with:
host: ${{secrets.WEB_SERVER_HOST}}
username: ${{secrets.WEB_SERVER_USERNAME}}
key: ${{secrets.WEB_SERVER_KEY}}
port: ${{secrets.WEB_SERVER_PORT}}
script: |
# [ℹ] Navigate to target project directory
cd web/scores
# [ℹ] Update the directory with latests changes
git pull origin enhance/feature-docker-deploy
# [ℹ] Run target makefile command
make update-scores-web
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
/.svelte-kit
/package
/gif
certs/*

# [CRITICAL TO BE UN-TRACKED]
.env
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"backgroundColor": "black",
"overviewRulerColor": "grey"
},
{
"text": "DOC:",
"color": "#ffffff",
"backgroundColor": "blue",
"overviewRulerColor": "grey"
},
{
"text": "IMPORTANT",
"color": "#ffffff",
Expand Down
38 changes: 38 additions & 0 deletions CONTRIBUTING/EXAMPLE_WIDGET.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!-- ===============
COMPONENT JS (w/ TS)
=================-->

<script lang="ts">

// ~~~~~~~~~~~~~~~~~~~~~
// COMPONENT VARIABLES
// ~~~~~~~~~~~~~~~~~~~~~

export const EXAMPLE_VALUE

const EXAMPLE_VALUE

// ~~~~~~~~~~~~~~~~~~~~~
// COMPONENT METHODS
// ~~~~~~~~~~~~~~~~~~~~~

function do_something() {}

// ~~~~~~~~~~~~~~~~~~~~~
// VIEWPORT CHANGES
// ~~~~~~~~~~~~~~~~~~~~~

</script>

<!-- ===============
COMPONENT HTML
=================-->

<!-- HTML GOES HERE -->

<!-- ===============
COMPONENT STYLE
=================-->

<style>
</style>
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ WORKDIR /app
COPY --from=build /app .
COPY . .

EXPOSE 3000
CMD ["node", "./build"]
EXPOSE 5055
# CMD ["node", "./build"]
CMD ["npm", "start"]
29 changes: 29 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# https://hub.docker.com/_/node

# ==== Builder Image
FROM node:16.17.0-alpine as build

WORKDIR /app

# [ℹ] Installs required node packages
COPY package.json package-lock.json ./
# RUN apk add --no-cache git
# [ℹ] Installs required APK packages:
# [ℹ] https://pkgs.alpinelinux.org/packages
# [ℹ] example-use: https://superuser.com/questions/1055060/how-to-install-a-specific-package-version-in-alpine
# [ℹ] example-use: https://superuser.com/questions/1198215/fixate-version-alpine-linux-apk-package-in-container
RUN apk add --no-cache \
python3=3.10.9-r0 \
make=4.3-r0 \
g++=11.2.1_git20220219-r2 \
&& npm i --omit=optional

# [ℹ] Builds node application
COPY . .

# Expose port 3000 for the SvelteKit app and 24678 for Vite's HMR
EXPOSE 5055
EXPOSE 24678

# CMD ["node", "./build"]
CMD ["npm", "run", "dev-docker"]
38 changes: 36 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# ===========
# PRODUCTION
# ===========

start:
echo 'Starting PROD container'
docker-compose -f docker-compose.yml up -d

log-listen:
echo 'Starting PROD container'
docker-compose -f docker-compose.yml up

update-scores-web:
echo 'Updating PROD Scores Web container...'
git pull origin enhance/feature-docker-deploy
-docker rm $$(docker stop $$(docker ps -a -q --filter="name=scores_scores_web_1" --format="{{.ID}}"))
-docker rmi $$(docker images -q scores_web)
-docker rmi $$(docker images --filter "dangling=true" -q --no-trunc)
docker-compose -f docker-compose.yml up -d

# ===========
# DEVELOPMENT
# ===========
Expand All @@ -6,9 +26,23 @@ dev-start:
echo 'Starting DEV Environment'
npm run dev
echo 'Removing Old DEV Logs'
rm -r ./datalog/
-rm -r ./datalog/*
echo 'DEV Ready!'

dev-docker-start:
echo 'Starting DEV - Docker Environment'
echo 'Removing Old DEV Logs'
-rm -r ./datalog/*
docker-compose -f docker-compose.dev.yml up
echo 'DEV Ready!'

dev-clean:
echo 'Removing Old DEV Logs'
rm -r ./datalog/
rm -r ./datalog/

# from Develop and assuming your master is up to date with origin/master
# git-post-main-pr:
# git checkout main
# git pull origin main
# git checkout dev
# git reset --hard main
49 changes: 42 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,31 @@ This project is dependent on the following libraries and technologies:

### Dev Environment

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
> There are a few ways in which you can start working with development, all listed below:

1. ⭐️ [Preferred]

Using `GitHub | Codespaces`. To get started simply launch the
`dev` branch and once the `codespace` has successfully loaded
check for `node` and `npm` to match those in the `package.json > engines`.
If versions do not match, run the following commands:

```
npm install -g [email protected]
npm install
```

---

2. `Local Dev`

Clone the latest `main` branch and begin development:

```bash
npm install (or `pnpm install` or `yarn`)
```

and start the development server:

```bash
npm run dev
Expand All @@ -56,15 +80,26 @@ npm run dev
npm run dev -- --open
```

### Dev Environment [Codespaces]
---

If you're using `codespaces` enabled for the `scores-platform` development - simply launch the
`dev` branch and once the `codespace` has successfully loaded run the following commands:
3. `Docker DEV`

If you do not have the supported/defined `node` and `npm` versions
installed on your local machine, you can opt to use the configured `Docker`
DEV environemnt.

For this you will need:
- `Docker Desktop` downloded on your local machine,
- `Makefile` (or `Node`)

```bash
make dev-docker-start

# OR if no Make installed
npm run docker-dev-up
```
npm install -g [email protected]
npm install
```

`NOTE:` 🔥 Hot-reload enabled for `Docker DEV`

### Production Environment

Expand Down
32 changes: 32 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Please refer https://aka.ms/HTTPSinContainer on how to setup an https developer certificate for your ASP .NET Core service.

version: '3.4'

services:

scores_web:
image: scores_web
restart: always
environment:
PORT: ${PORT}
VITE_HASURA_DB_URL: ${VITE_HASURA_DB_URL}
VITE_HASURA_DB_TOKEN: ${VITE_HASURA_DB_TOKEN}
VITE_FIREBASE_DB_API_KEY: ${VITE_FIREBASE_DB_API_KEY}
VITE_FIREBASE_DB_AUTH_DOMAIN: ${VITE_FIREBASE_DB_AUTH_DOMAIN}
VITE_FIREBASE_DB_PROJECT_ID: ${VITE_FIREBASE_DB_PROJECT_ID}
VITE_FIREBASE_DB_DATABASE_URL: ${VITE_FIREBASE_DB_DATABASE_URL}
VITE_REDIS_HOST: ${VITE_REDIS_HOST}
VITE_REDIS_PORT: ${VITE_REDIS_PORT}
VITE_REDIS_PASS: ${VITE_REDIS_PASS}
VITE_REDIS_CACHE_DB: ${VITE_REDIS_CACHE_DB}
VITE_REDIS_BULL_DB: ${VITE_REDIS_BULL_DB}
build:
context: .
dockerfile: ./Dockerfile.dev
# NOTE: enalbe-DEV hot-reload [INPORTANT]
volumes:
- .:/app
- /app/node_modules # path as its own volume to avoid copying over local Node modules to Docker
ports:
- 5055:5055
- 24678:24678
31 changes: 31 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Please refer https://aka.ms/HTTPSinContainer on how to setup an https developer certificate for your ASP .NET Core service.

version: '3.4'

services:

scores_web:
image: scores_web
restart: always
environment:
PORT: ${PORT}
VITE_HASURA_DB_URL: ${VITE_HASURA_DB_URL}
VITE_HASURA_DB_TOKEN: ${VITE_HASURA_DB_TOKEN}
VITE_FIREBASE_DB_API_KEY: ${VITE_FIREBASE_DB_API_KEY}
VITE_FIREBASE_DB_AUTH_DOMAIN: ${VITE_FIREBASE_DB_AUTH_DOMAIN}
VITE_FIREBASE_DB_PROJECT_ID: ${VITE_FIREBASE_DB_PROJECT_ID}
VITE_FIREBASE_DB_DATABASE_URL: ${VITE_FIREBASE_DB_DATABASE_URL}
VITE_REDIS_HOST: ${VITE_REDIS_HOST}
VITE_REDIS_PORT: ${VITE_REDIS_PORT}
VITE_REDIS_PASS: ${VITE_REDIS_PASS}
VITE_REDIS_CACHE_DB: ${VITE_REDIS_CACHE_DB}
VITE_REDIS_BULL_DB: ${VITE_REDIS_BULL_DB}
build:
context: .
dockerfile: ./Dockerfile
volumes:
- ./certs:/certs # IMPORTANT
ports:
- 5055:5055
- 443:443 # IMPORTANT
- 80:80 # IMPORTANT
40 changes: 31 additions & 9 deletions my-server.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// [ℹ] https://github.com/sveltejs/kit/tree/master/packages/adapter-node#custom-server
// [ℹ] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

import express from 'express';
import http from 'http';
import https from 'https';

import { handler } from './build/handler.js';
// import sslRedirect from 'heroku-ssl-redirect';
import compression from 'compression'; // https://expressjs.com/en/resources/middleware/compression.html
import * as sslify from 'express-sslify';
import * as requestIp from 'request-ip'; // https://www.npmjs.com/package/request-ip

import fs from 'fs';

const options = {
key: fs.readFileSync('./certs/privkey.pem'),
cert: fs.readFileSync('./certs/cert.pem'),
}
;

const app = express();

/**
Expand Down Expand Up @@ -65,12 +75,12 @@ app.get('/getClientIP', (req, res) => {
* [ℹ] https://jaketrent.com/post/https-redirect-node-heroku
* [ℹ] https://webdva.github.io/how-to-force-express-https-tutorial
*/
app.use((req, res, next) => {
if (req.header('x-forwarded-proto') !== 'https')
res.redirect(`https://${req.header('host')}${req.url}`);
else
next();
});
// app.use((req, res, next) => {
// if (req.header('x-forwarded-proto') !== 'https')
// res.redirect(`https://${req.header('host')}${req.url}`);
// else
// next();
// });

/**
* [ℹ] https://www.npmjs.com/package/express-sslify
Expand All @@ -91,6 +101,18 @@ app.use(handler);
* [ℹ] initialize app;
* [ℹ] https://stackoverflow.com/questions/15693192/heroku-node-js-error-web-process-failed-to-bind-to-port-within-60-seconds-o
*/
app.listen(process.env.PORT || 5000, () => {
console.log('listening on port 5000');
// app.listen(process.env.PORT, () => {
// console.log(`listening on port ${process.env.PORT}`);
// });

// ~~~~~~~~~~~~~~~~~~~~~~
// APP SPIN-UP [PROD] [V2]
// ~~~~~~~~~~~~~~~~~~~~~~

http.createServer(app).listen(80, () => {
console.log(`[HTTP | Server]: Server is running on port: ${80}`);
});

https.createServer(options, app).listen(443, () => {
console.log(`[HTTPS | Server]: Server is running on port: ${443}`);
});
Loading