Skip to content

Commit

Permalink
Merge branch 'main' into add-go-linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradumnasaraf committed Oct 24, 2024
2 parents d41a9c8 + eb6869d commit f10ccb8
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 124 deletions.
80 changes: 0 additions & 80 deletions .github/workflows/ci.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .nixpacks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"phases": {
"install": {
"cmds": [
"cd server",
"go mod download"
]
},
"build": {
"cmds": [
"cd server",
"go build -o app"
]
},
"start": {
"cmd": "./server/app"
}
}
}

9 changes: 9 additions & 0 deletions client/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Dockerfile
.dockerignore
.gitignore
.git
README.md
frontend.dockerfile

build
node_modules
13 changes: 13 additions & 0 deletions client/client.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:alpine3.19

WORKDIR /app

COPY client/package*.json ./

RUN npm install --ignore-platform

COPY client/ .

EXPOSE 5173

CMD [ "npm" , "run" , "dev" ]
66 changes: 33 additions & 33 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
{
"name": "client",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@chakra-ui/react": "^2.10.3",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@tanstack/react-query": "^5.59.15",
"framer-motion": "^11.11.9",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.3.0"
},
"devDependencies": {
"@eslint/js": "^9.11.1",
"@types/react": "^18.3.10",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.2",
"eslint": "^9.11.1",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.12",
"globals": "^15.9.0",
"typescript": "^5.5.3",
"typescript-eslint": "^8.7.0",
"vite": "^5.4.8"
}
"name": "client",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --host",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@chakra-ui/react": "^2.10.3",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@tanstack/react-query": "^5.59.15",
"framer-motion": "^11.11.9",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.3.0"
},
"devDependencies": {
"@eslint/js": "^9.11.1",
"@types/react": "^18.3.10",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.2",
"eslint": "^9.11.1",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.12",
"globals": "^15.9.0",
"typescript": "^5.5.3",
"typescript-eslint": "^8.7.0",
"vite": "^5.4.8"
}
}
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
backend:
container_name: go-server
build:
context: .
dockerfile: server/server.dockerfile
environment:
MONGODB_URI: <db_connection_string>
PORT: "5000"
ENV: production
ports:
- "5000:5000"

healthcheck:
interval: 2s
test: "exit 0"

frontend:
container_name: react-frontend
build:
context: .
dockerfile: client/client.dockerfile

ports:
- "5173:5173"
depends_on:
backend:
condition: service_healthy
3 changes: 3 additions & 0 deletions server/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tmp
backend.dockerfile
.dockerignore
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions main.go → server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"

"github.com/gofiber/fiber/v2"
"github.com/joho/godotenv"
"github.com/gofiber/fiber/v2/middleware/cors"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
Expand All @@ -26,11 +26,11 @@ func main() {
fmt.Println("hello world")

if os.Getenv("ENV") != "production" {
// Load the .env file if not in production
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Error loading .env file:", err)
}
// // Load the .env file if not in production
// err := godotenv.Load(".env")
// if err != nil {
// log.Fatal("Error loading .env file:", err)
// }
}

MONGODB_URI := os.Getenv("MONGODB_URI")
Expand All @@ -54,10 +54,10 @@ func main() {

app := fiber.New()

// app.Use(cors.New(cors.Config{
// AllowOrigins: "http://localhost:5173",
// AllowHeaders: "Origin,Content-Type,Accept",
// }))
app.Use(cors.New(cors.Config{
AllowOrigins: "http://localhost:5173",
AllowHeaders: "Origin,Content-Type,Accept",
}))

app.Get("/api/todos", getTodos)
app.Post("/api/todos", createTodo)
Expand All @@ -70,7 +70,7 @@ func main() {
}

if os.Getenv("ENV") == "production" {
app.Static("/", "./client/dist")
app.Static("/", "./dist")
}

log.Fatal(app.Listen("0.0.0.0:" + port))
Expand Down
21 changes: 21 additions & 0 deletions server/server.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# use official Golang image
FROM golang:alpine3.20

# set working directory
WORKDIR /app
RUN mkdir dist

# Copy the source code
COPY server/ .
COPY client/dist ./dist
# Download and install the dependencies
RUN go mod tidy

# Build the Go app
RUN go build -o todoApp .

#EXPOSE the port
EXPOSE 5000

# Run the executable
CMD ["./todoApp"]

0 comments on commit f10ccb8

Please sign in to comment.