diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..496ee2c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file diff --git a/dockerized/nextcloud-aio/compose.yaml b/dockerized/nextcloud-aio/compose.yaml new file mode 100644 index 0000000..a6b1454 --- /dev/null +++ b/dockerized/nextcloud-aio/compose.yaml @@ -0,0 +1,34 @@ +version: "3.8" + +#Imported from https://github.com/nextcloud/all-in-one/discussions/575#discussion-4055615 + +services: + caddy: + image: caddy:alpine + restart: unless-stopped + container_name: caddy + volumes: + - ./Caddyfile:/etc/caddy/Caddyfile + - ./certs:/certs + - ./config:/config + - ./data:/data + - ./sites:/srv + network_mode: "host" + + nextcloud: + image: nextcloud/all-in-one:latest + restart: unless-stopped + container_name: nextcloud-aio-mastercontainer + ports: + - "8080:8080" + environment: + - APACHE_PORT=11000 + volumes: + - nextcloud_aio_mastercontainer:/mnt/docker-aio-config + - /var/run/docker.sock:/var/run/docker.sock:ro + depends_on: + - caddy + +volumes: + nextcloud_aio_mastercontainer: + name: nextcloud_aio_mastercontainer \ No newline at end of file diff --git a/dockerized/nextcloud-aio/docker_run.sh b/dockerized/nextcloud-aio/docker_run.sh new file mode 100644 index 0000000..4f3e352 --- /dev/null +++ b/dockerized/nextcloud-aio/docker_run.sh @@ -0,0 +1,16 @@ +#! /usr/bin/bash +echo "Installing denpendency packages..." + +docker run \ +--init \ +--sig-proxy=false \ +--name nextcloud-aio-mastercontainer \ +--restart always \ +--publish 8080:8080 \ +--env APACHE_PORT=11000 \ +--env APACHE_IP_BINDING=0.0.0.0 \ +--env APACHE_ADDITIONAL_NETWORK="" \ +--env SKIP_DOMAIN_VALIDATION=false \ +--volume nextcloud_aio_mastercontainer:/mnt/docker-aio-config \ +--volume /var/run/docker.sock:/var/run/docker.sock:ro \ +nextcloud/all-in-one:latest \ No newline at end of file diff --git a/dockerized/simple_site/Dockerfile b/dockerized/simple_site/Dockerfile new file mode 100644 index 0000000..5c5d2e3 --- /dev/null +++ b/dockerized/simple_site/Dockerfile @@ -0,0 +1,14 @@ +FROM node:14 + +WORKDIR /app + +COPY server.js . +COPY index.html . +#COPY images ./images +COPY package.json . + +RUN npm install + +EXPOSE 3000 + +CMD ["node","server.js"] \ No newline at end of file diff --git a/dockerized/simple_site/README.md b/dockerized/simple_site/README.md new file mode 100644 index 0000000..8e74383 --- /dev/null +++ b/dockerized/simple_site/README.md @@ -0,0 +1,16 @@ +### Simple Site +Simple dockerized application using Node.js behind NGINX in order to securely serve a static webapp + +**NB: compose uses build, thus is not suitable for swarm** + +#### Details + +Dockerized app : + Node.js + application server.js (listens to 3000) + serves index.html + depending from packages + +Compose : + Defined 3 services from Dockerized app + Configured NGINX (listens to 8081) to proxy diff --git a/dockerized/simple_site/docker-compose.yaml b/dockerized/simple_site/docker-compose.yaml new file mode 100644 index 0000000..d674ab3 --- /dev/null +++ b/dockerized/simple_site/docker-compose.yaml @@ -0,0 +1,48 @@ +version: '3' + +networks: + cluster: + driver: bridge + +services: + +# 3 versions of the same app responding to host's 3001-3 + app1: + build: . + environment: + - APP_NAME=App1 + ports: + - "3000" + networks: + - cluster + + app2: + build: . + environment: + - APP_NAME=App2 + ports: + - "3000" + networks: + - cluster + + app3: + build: . + environment: + - APP_NAME=App3 + ports: + - "3000" + networks: + - cluster + + + # --- NGINX --- + nginx: + image: nginx:latest + ports: + - '8081:80' + volumes: + - ./nginx/config.conf:/etc/nginx/nginx.conf:ro + healthcheck: + test: ["CMD", "service", "nginx", "status"] + networks: + - cluster diff --git a/dockerized/simple_site/index.html b/dockerized/simple_site/index.html new file mode 100644 index 0000000..73e9c52 --- /dev/null +++ b/dockerized/simple_site/index.html @@ -0,0 +1,114 @@ + + + + + + + Beautiful Landing Page + + + + +
+
+ +
+

TechWorld with Nana Programs

+
+
+ Service 1 +

DevOps Bootcamp

+

Finally learn with structured guided course, all DevOps tools together

+
+
+ Service 2 +

Software Development LifeCycle Course

+

Learn the entire software Development lifecycle, from developing, to testing, to provisioning server and deploying

+
+
+ Service 3 +

DevSecOps Bootcamp

+

If you wanna become a DevOps engineer on steroids, you can face this advanced bootcamp

+
+
+
+ + + + diff --git a/dockerized/simple_site/nginx/config.conf b/dockerized/simple_site/nginx/config.conf new file mode 100644 index 0000000..92ccce2 --- /dev/null +++ b/dockerized/simple_site/nginx/config.conf @@ -0,0 +1,59 @@ +# Main context (this is the global configuration) +worker_processes 4; + +events { + worker_connections 1024; +} + +http { + include mime.types; + + # Upstream block to define the Node.js backend servers + # Servers name come from compose definition + + upstream nodejs_cluster { + server app1:3000; + server app2:3000; + server app3:3000; + } + + + #TODO manage certs + # server { + # listen 443 ssl; # Listen on port 443 for HTTPS + # server_name localhost; + + # # SSL certificate settings + # ssl_certificate /Users/nana/nginx-certs/nginx-selfsigned.crt; + # ssl_certificate_key /Users/nana/nginx-certs/nginx-selfsigned.key; + + # # Proxying requests to Node.js cluster + # location / { + # proxy_pass http://nodejs_cluster; + # proxy_set_header Host $host; + # proxy_set_header X-Real-IP $remote_addr; + # } + # } + + # Optional server block for HTTP to HTTPS redirection + server { + listen 80; # Listen on port 80 for HTTP + server_name *.sselab.ddns.net; + + + location / { + # Redirect all HTTP traffic to HTTPS + # TODO requires https + # return 301 https://$host$request_uri; + + proxy_pass http://nodejs_cluster; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + } +} diff --git a/dockerized/simple_site/package.json b/dockerized/simple_site/package.json new file mode 100644 index 0000000..b3f2d9c --- /dev/null +++ b/dockerized/simple_site/package.json @@ -0,0 +1,16 @@ +{ + "name": "simple_site", + "version": "1.0.0", + "description": "A Node.js application serving a static HTML file, used for load balancing with NGINX.", + "main": "server.js", + "scripts": { + "start": "node server.js" + }, + "author": "Fabio Sinibaldi", + "license": "MIT", + "dependencies": { + "express": "^4.17.1", + "path": "^0.12.7" + } + } + \ No newline at end of file diff --git a/dockerized/simple_site/server.js b/dockerized/simple_site/server.js new file mode 100644 index 0000000..57780e7 --- /dev/null +++ b/dockerized/simple_site/server.js @@ -0,0 +1,18 @@ +const express = require('express'); +const path = require('path'); +const app = express(); +const port = 3000; + +// Defined in compose file +const appName = process.env.APP_NAME + +app.use('/images', express.static(path.join(__dirname, 'images'))); + +app.use('/', (req, res) => { + res.sendFile(path.join(__dirname, 'index.html')); + console.log(`Request served by ${appName}`); +}); + +app.listen(port, () => { + console.log(`${appName} is listening on port ${port}`); +});