diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..da747d7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node:12 + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +EXPOSE 3000 + +CMD ["npm", "start"] diff --git a/README.md b/README.md index 3fcf031..d50dcc7 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,11 @@ Note: I'm assuming you're running Ubuntu 22.04. * Get nodejs and npm ready - Run `sudo apt update` and `sudo apt install nodejs`. Check that worked with `node -v`. - Run `sudo apt install npm`. Check that worked with `npm -v`. -* Init an npm project. +* Init an npm project: `npm init -y` +* Modify `package.json`: you might want to add dependencies. +* Potentially add a `start script`. + +## How to run + +* You can get the dev containers up and running with `npm run start:containers`. +* If you would rather only run the express app locally, you can just do `npm run start` instead. diff --git a/caddy/Caddyfile b/caddy/Caddyfile new file mode 100644 index 0000000..da44ac9 --- /dev/null +++ b/caddy/Caddyfile @@ -0,0 +1,3 @@ +:80 { + reverse_proxy express:3000 +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..977dfb0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: '3' + +services: + express: + build: . + ports: + - "3000:3000" + + caddy: + image: caddy:2 + ports: + - "80:80" + volumes: + - ./caddy:/etc/caddy + depends_on: + - express diff --git a/index.js b/index.js index ec7bd78..461f3c5 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ const app = express(); const port = 3000; app.get('/', (req, res) => { - res.send('Hello World!'); + res.send("Hello World! We're live"); }); app.listen(port, () => { diff --git a/package.json b/package.json index d3ed229..c907c5d 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,8 @@ "main": "index.js", "scripts": { "start": "node index.js", + "start:containers": "docker compose up -d --build", + "stop:containers": "docker compose down", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [],