Skip to content

Commit

Permalink
feat: create docker compose with nginx, node and mysql configured
Browse files Browse the repository at this point in the history
  • Loading branch information
diegosurita committed Feb 9, 2024
0 parents commit 5b557e6
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.mysql
4 changes: 4 additions & 0 deletions bootstrap.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE IF NOT EXISTS people (
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
43 changes: 43 additions & 0 deletions default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
server {
listen 80;
listen [::]:80;
server_name localhost;

#access_log /var/log/nginx/host.access.log main;

location / {
proxy_pass http://fullcycle-node:3000;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
39 changes: 39 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
version: '3.8'

services:
node:
image: node:20-alpine
container_name: fullcycle-node
command: npm run start
volumes:
- .:/app
working_dir: /app
expose:
- "3000"
depends_on:
- db

nginx:
image: nginx:1.25.3-alpine
container_name: fullcycle-nginx
ports:
- "8080:80"
expose:
- "80"
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- node

db:
image: mysql:8.3
container_name: fullcycle-mysql
ports:
- "3306:3306"
volumes:
- ./.mysql:/var/lib/mysql
- bootstrap.sql:/docker-entrypoint-initdb.d/1.sql
environment:
MYSQL_USER: "root"
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: fullcycle
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const http = require("node:http");

const hostname = "0.0.0.0";
const port = 3000;

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader("Content-Type", "text/plain");
res.end("<h1>Fullcycle Rocks!</h1>");
});

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
13 changes: 13 additions & 0 deletions package-lock.json

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

19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "desafio-proxy-fullcycle",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/diegosurita/desafio-proxy-fullcycle.git"
},
"author": "Diego Surita <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/diegosurita/desafio-proxy-fullcycle/issues"
},
"homepage": "https://github.com/diegosurita/desafio-proxy-fullcycle#readme"
}

0 comments on commit 5b557e6

Please sign in to comment.