Skip to content

Commit 57e13d7

Browse files
fix errors in the production rails dockerfile
0 parents  commit 57e13d7

File tree

10 files changed

+1004
-0
lines changed

10 files changed

+1004
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
FROM mcr.microsoft.com/devcontainers/typescript-node:22-bookworm

.devcontainer/devcontainer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile",
4+
"context": ".."
5+
},
6+
"features": {
7+
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
9+
"ghcr.io/devcontainers/features/aws-cli:1": {}
10+
}
11+
}

.github/workflows/deploy.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
environment: playground
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- name: Checkout Repo
18+
uses: actions/checkout@v4
19+
20+
- name: Deploy
21+
uses: DefangLabs/[email protected]

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Node.js & SocketIO
2+
3+
[![1-click-deploy](https://defang.io/deploy-with-defang.png)](https://portal.defang.dev/redirect?url=https%3A%2F%2Fgithub.com%2Fnew%3Ftemplate_name%3Dsample-nodejs-chatroom-template%26template_owner%3DDefangSamples)
4+
5+
This is a minimal chat application that shows how to use Socket.IO with Node.js with minimal code deployed with Defang.
6+
7+
## Prerequisites
8+
9+
Install the Defang CLI by following the instructions in the [Defang CLI documentation](https://docs.defang.io/docs/getting-started).
10+
11+
## Build and run the application
12+
13+
If you have environment variables configured for your [own cloud account](https://docs.defang.io/docs/concepts/defang-byoc), this will deploy the application to your cloud account, otherwise it will deploy to the Defang cloud.
14+
15+
```sh
16+
defang compose up
17+
```
18+
19+
---
20+
21+
Title: Node.js & SocketIO
22+
23+
Short Description: A minimal chat application that shows how to use Socket.IO with Node.js.
24+
25+
Tags: Node.js, Chat, Socket.IO, JavaScript
26+
27+
Languages: nodejs

app/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use the slim version of Node.js on Debian Bookworm as the base image
2+
FROM node:20-bookworm-slim
3+
4+
RUN apt-get update -qq \
5+
&& apt-get install -y curl \
6+
&& apt-get clean \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
# Set the working directory to /app
10+
WORKDIR /app
11+
12+
# Copy package.json and package-lock.json into the container at /app
13+
COPY package*.json ./
14+
15+
# Install any needed packages specified in package.json
16+
RUN npm install
17+
18+
# Bundle app source
19+
COPY . .
20+
21+
# Make port 3000 available to the world outside this container
22+
EXPOSE 3000
23+
24+
# Run the app when the container launches
25+
CMD ["node", "main.js"]

app/index.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Simple Chat App</title>
7+
</head>
8+
<body>
9+
10+
<input type="text" id="name" placeholder="Enter your name" required>
11+
<input type="text" id="message" placeholder="Enter a message" required>
12+
<button onclick="sendMessage()">Send</button>
13+
14+
<ul id="messages"></ul>
15+
16+
<script src="/socket.io/socket.io.js"></script>
17+
<script>
18+
var socket = io();
19+
20+
socket.on('message', function(msg){
21+
var ul = document.getElementById('messages');
22+
var li = document.createElement('li');
23+
li.appendChild(document.createTextNode(msg.name + ': ' + msg.message));
24+
ul.appendChild(li);
25+
});
26+
27+
function sendMessage(){
28+
var name = document.getElementById('name').value;
29+
var message = document.getElementById('message').value;
30+
socket.emit('message', { name: name, message: message });
31+
}
32+
</script>
33+
34+
</body>
35+
</html>

app/main.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const express = require('express');
2+
const http = require('http');
3+
const app = express();
4+
const server = http.createServer(app);
5+
const io = require('socket.io')(server);
6+
const bodyParser = require('body-parser');
7+
const path = require('path');
8+
9+
app.use(bodyParser.json());
10+
app.use(bodyParser.urlencoded({ extended: true }));
11+
12+
io.on('connection', (socket) => {
13+
socket.on('message', ({name, message}) => {
14+
io.emit('message', {name, message});
15+
});
16+
});
17+
18+
app.get('/', (req, res) => {
19+
res.sendFile(path.join(__dirname, 'index.html'));
20+
});
21+
22+
const port = process.env.PORT || 3000;
23+
24+
server.listen(port, () => {
25+
console.log('Server started on port ' + port);
26+
});

0 commit comments

Comments
 (0)