Skip to content

Commit 44268b6

Browse files
committed
ci: publish workflow
1 parent 7f30c04 commit 44268b6

File tree

11 files changed

+194
-141
lines changed

11 files changed

+194
-141
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Build and Push Docker Images
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
build-and-push:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
packages: write
13+
14+
steps:
15+
- name: Checkout repo
16+
uses: actions/checkout@v3
17+
18+
- name: Log in to GitHub Container Registry
19+
uses: docker/login-action@v2
20+
with:
21+
registry: ghcr.io
22+
username: ${{ github.actor }}
23+
password: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Build and push server image
26+
uses: docker/build-push-action@v5
27+
with:
28+
context: .
29+
file: ./server/Dockerfile
30+
push: true
31+
tags: ghcr.io/${{ github.repository }}/server:latest
32+
33+
- name: Build and push client image
34+
uses: docker/build-push-action@v5
35+
with:
36+
context: ./client
37+
file: ./client/Dockerfile
38+
push: true
39+
tags: ghcr.io/${{ github.repository }}/client:latest
40+
build-args: |
41+
VITE_SOCKET_URL=wss://bingo.oops.wtf/socket.io

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/client/node_modules/
22
/server/node_modules/
33
/client/.env
4+
/server/dist
5+
/client/build

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# BINGOLFY
22

33
A multiplayer web app game of BINGO.
4-
Access the game at: https://bingolfy.onrender.com
4+
Access the game at:
5+
> https://bingolfy.onrender.com
6+
> https://bingo.oops.wtf
57
68

79
> [!NOTE]

client/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# build stage
22
FROM node:20-alpine AS build
33
WORKDIR /app
4+
ARG VITE_SOCKET_URL
5+
ENV VITE_SOCKET_URL=$VITE_SOCKET_URL
46
COPY package*.json ./
57
RUN npm ci
68
COPY . .

client/src/App.tsx

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,67 +9,69 @@ import { auth } from "./firebase";
99
import { useAuthState } from "react-firebase-hooks/auth";
1010
import { useEffect, useState } from 'react';
1111

12-
const socket = io.connect(
13-
import.meta.env.VITE_DEBUG ?
14-
"http://localhost:5174" :
15-
"https://bingolfy-backend.onrender.com/"
16-
);
12+
const socketUrl = import.meta.env.VITE_SOCKET_URL;
13+
14+
if (!socketUrl) {
15+
throw new Error("Build failed: VITE_SOCKET_URL is missing!");
16+
}
17+
18+
const socket = io.connect(socketUrl);
1719

1820
function App() {
19-
const [user] = useAuthState(auth);
20-
const [userDetails, setUserDetails] = useState({});
21-
const [anonUser, setAnonUser] = useState();
22-
const [grid, setGrid] = useState();
23-
const [room, setRoom] = useState();
24-
const [playingUsers, setPlayingUsers] = useState([]);
21+
const [user] = useAuthState(auth);
22+
const [userDetails, setUserDetails] = useState({});
23+
const [anonUser, setAnonUser] = useState();
24+
const [grid, setGrid] = useState();
25+
const [room, setRoom] = useState();
26+
const [playingUsers, setPlayingUsers] = useState([]);
2527

26-
useEffect(() => {
27-
if (user || anonUser) {
28-
setUserDetails({
29-
name: user?.displayName || anonUser,
30-
email: user?.email,
31-
photo: user?.photoURL,
32-
uid: user?.uid || (Math.random()*100)
33-
})
34-
}
35-
}, [user, anonUser]);
28+
useEffect(() => {
29+
if (user || anonUser) {
30+
setUserDetails({
31+
name: user?.displayName || anonUser,
32+
email: user?.email,
33+
photo: user?.photoURL,
34+
uid: user?.uid || (Math.random() * 100)
35+
})
36+
}
37+
}, [user, anonUser]);
3638

37-
useEffect(() => {
38-
socket.on("user_joined", setPlayingUsers);
39-
}, []);
39+
useEffect(() => {
40+
socket.on("user_joined", setPlayingUsers);
41+
}, []);
4042

41-
return (
42-
<div className="App">
43-
<NavBar />
43+
return (
44+
<div className="App">
45+
<NavBar />
4446

45-
<div>
46-
{
47-
(user || anonUser)
48-
?
49-
(!room ?
50-
<Room name={userDetails.name} room={room} setRoom={setRoom} socket={socket} /> :
51-
(
52-
!grid ?
53-
<GameSetup
54-
setGrid={setGrid}
55-
/> :
56-
<Game
57-
playingUsers={playingUsers}
58-
room={room}
59-
userDetails={userDetails}
60-
socket={socket}
61-
grid={grid}
62-
setGrid={setGrid}
63-
/>
64-
)
65-
)
66-
:
67-
<Login setAnonUser={setAnonUser} />
68-
}
69-
</div>
47+
<div>
48+
{
49+
(user || anonUser)
50+
?
51+
(!room ?
52+
<Room name={userDetails.name} room={room} setRoom={setRoom} socket={socket} /> :
53+
(
54+
!grid ?
55+
<GameSetup
56+
setGrid={setGrid}
57+
/> :
58+
<Game
59+
playingUsers={playingUsers}
60+
room={room}
61+
userDetails={userDetails}
62+
socket={socket}
63+
grid={grid}
64+
setGrid={setGrid}
65+
/>
66+
)
67+
)
68+
:
69+
<Login setAnonUser={setAnonUser} />
70+
}
71+
</div>
7072

71-
</div>
72-
)
73+
</div>
74+
)
7375
}
7476

7577
export default App;

server/Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
FROM node:20-alpine
22
WORKDIR /app
3-
COPY package*.json ./
4-
RUN npm ci
5-
COPY . .
3+
COPY server/package*.json ./
4+
RUN npm install
5+
COPY server/tsconfig.json ./
6+
COPY server/src ./src
7+
RUN npm run build
68
EXPOSE 3000
79
CMD ["npm", "start"]

server/package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
{
2-
"name": "server",
3-
"version": "1.0.0",
4-
"description": "Tic tac toe",
5-
"main": "index.js",
6-
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
8-
"start": "node src/index.js",
9-
"dev": "DEBUG=1 nodemon -x ts-node src/index.ts",
10-
"build": "tsc"
11-
},
12-
"keywords": [],
13-
"author": "",
14-
"license": "ISC",
15-
"dependencies": {
16-
"@types/cors": "^2.8.17",
17-
"cors": "^2.8.5",
18-
"express": "^4.18.2",
19-
"nodemon": "^3.0.1",
20-
"socket.io": "^4.7.2"
21-
},
22-
"devDependencies": {
23-
"@types/express": "^4.17.21",
24-
"ts-node": "^10.9.2",
25-
"typescript": "^5.4.5"
26-
}
2+
"name": "server",
3+
"version": "1.0.0",
4+
"description": "Tic tac toe",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"build": "tsc",
9+
"start": "node dist/index.js",
10+
"dev": "DEBUG=1 nodemon -x ts-node src/index.ts"
11+
},
12+
"keywords": [],
13+
"author": "",
14+
"license": "ISC",
15+
"dependencies": {
16+
"@types/cors": "^2.8.17",
17+
"cors": "^2.8.5",
18+
"express": "^4.18.2",
19+
"nodemon": "^3.0.1",
20+
"socket.io": "^4.7.2"
21+
},
22+
"devDependencies": {
23+
"@types/express": "^4.17.21",
24+
"ts-node": "^10.9.2",
25+
"typescript": "^5.4.5"
26+
}
2727
}

0 commit comments

Comments
 (0)