diff --git a/Dockerfile.core b/Dockerfile.core new file mode 100644 index 0000000..474e896 --- /dev/null +++ b/Dockerfile.core @@ -0,0 +1,20 @@ +# docker build -f Dockerfile.core -t einote:core-0.1.0 . + +# Stage 1: Build the Go application +FROM golang:1.23 AS builder + +WORKDIR /app +COPY core/go.mod core/go.sum ./ +RUN go mod download +COPY core/ . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o einote cmd/app/main.go + +# Stage 2: Run the Go application +FROM alpine:latest + +COPY --from=builder /app/einote /einote +RUN touch .env + +EXPOSE 8080 + +CMD ["/einote"] diff --git a/Dockerfile.ui b/Dockerfile.ui new file mode 100644 index 0000000..3b71ffc --- /dev/null +++ b/Dockerfile.ui @@ -0,0 +1,36 @@ +# docker build -f Dockerfile.ui -t einote:ui-0.1.0 . + +# build fe +FROM node:18-alpine AS build_stage + +# Install additional dependencies for Node.js on Alpine +RUN apk add --no-cache libc6-compat + +WORKDIR /fe + +COPY ./ui/package.json \ + ./ui/package-lock.json \ + ./ui/postcss.config.js \ + ./ui/tailwind.config.js \ + ./ui/tsconfig.json \ + ./ + +COPY ./ui/src ./src +COPY ./ui/public ./public + +RUN npm install --loglevel info + +# backend api will be proxied in nginx +ENV REACT_APP_BACKEND_API=http://localhost:4848/api + +RUN npm run build --loglevel info + +# build nginx to serve FE +FROM nginx:alpine3.19-slim + +COPY --from=build_stage /fe/build /usr/share/nginx/html + +COPY ./nginx.fe.conf /etc/nginx/conf.d/default.conf + +EXPOSE 3000 +CMD ["nginx", "-g", "daemon off;"] diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..f770f68 --- /dev/null +++ b/build.sh @@ -0,0 +1,9 @@ +export VERSION=0.1.0 + +buildUiCmd="docker build -f Dockerfile.ui -t einote:ui-$VERSION ." +echo "##### RUNNING: $buildUiCmd" +eval $buildUiCmd + +buildCoreCmd="docker build -f Dockerfile.core -t einote:core-$VERSION ." +echo "##### RUNNING: $buildCoreCmd" +eval $buildCoreCmd diff --git a/core/go.mod b/core/go.mod index b8a03ab..1cac7ce 100644 --- a/core/go.mod +++ b/core/go.mod @@ -1,6 +1,6 @@ module core -go 1.23.0 +go 1.23 require ( github.com/Masterminds/squirrel v1.5.4 diff --git a/core/go.sum b/core/go.sum index c1d11c5..1983b0f 100644 --- a/core/go.sum +++ b/core/go.sum @@ -1,5 +1,6 @@ github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM= github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -13,7 +14,9 @@ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhR github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA= github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..26e5cbd --- /dev/null +++ b/deploy.sh @@ -0,0 +1,4 @@ +# Run database migration +# migrate -database postgres://root:root@localhost:7432/einote?sslmode=disable -path ./migrations up + +docker compose up -d --force-recreate \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index fd33480..048650a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,5 +18,51 @@ services: interval: 30s timeout: 10s retries: 5 + # ports: + # - "7432:5432" + + einote-be: + image: einote:core-0.1.0 + container_name: einote-be + restart: unless-stopped + environment: + PORT: 8080 + DB_USER: root + DB_PASSWORD: root + DB_NAME: einote + DB_HOST: einote-db + DB_PORT: 5432 + TABLE_NOTE: note + TABLE_NOTEBOOK: notebook + # ports: + # - 8080:8080 + networks: + - default + depends_on: + - einote-db + + einote-fe: + image: einote:ui-0.1.0 + container_name: einote-fe + restart: unless-stopped + # ports: + # - 3000:3000 + volumes: + - ./nginx.fe.conf:/etc/nginx/conf.d/default.conf:ro + networks: + - default + depends_on: + - einote-be + + einote-proxy: + image: nginx:alpine3.19-slim + container_name: einote-px + restart: unless-stopped ports: - - "7432:5432" \ No newline at end of file + - 4848:80 # changing port? don't forget adjust REACT_APP_BACKEND_API in Dockerfile.ui + networks: + - default + depends_on: + - einote-fe + volumes: + - ./nginx.main.conf:/etc/nginx/conf.d/default.conf diff --git a/nginx.fe.conf b/nginx.fe.conf new file mode 100644 index 0000000..3419dcf --- /dev/null +++ b/nginx.fe.conf @@ -0,0 +1,13 @@ +server { + listen 3000; + listen [::]:3000; + server_name localhost; + + access_log /var/log/nginx/host.access.log main; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } +} diff --git a/nginx.main.conf b/nginx.main.conf new file mode 100644 index 0000000..419bf32 --- /dev/null +++ b/nginx.main.conf @@ -0,0 +1,20 @@ +server { + listen 80; + listen [::]:80; + + # listen 443 ssl; + + server_name 0.0.0.0; + + access_log /var/log/nginx/host.access.log main; + + # ssl_certificate /ssl/certificate_merge.crt; + # ssl_certificate_key /ssl/private.key; + + location / { + proxy_pass http://einote-fe:3000; + } + location /api/ { + proxy_pass http://einote-be:8080/; + } +} \ No newline at end of file diff --git a/ui/.env.example b/ui/.env.example new file mode 100644 index 0000000..feba24d --- /dev/null +++ b/ui/.env.example @@ -0,0 +1 @@ +REACT_APP_BACKEND_API= \ No newline at end of file diff --git a/ui/src/App.tsx b/ui/src/App.tsx index 250efa6..cdddc70 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -6,7 +6,7 @@ function App() { const webTheme = localStorage.getItem("theme") return ( -
+
); diff --git a/ui/src/core/Provider.tsx b/ui/src/core/Provider.tsx index 2dc0209..13f4af2 100644 --- a/ui/src/core/Provider.tsx +++ b/ui/src/core/Provider.tsx @@ -8,8 +8,9 @@ import NoteAPI from "./api/note"; function Provider() { - const notebookApi = new NotebookAPI("http://localhost:2001", false) - const noteApi = new NoteAPI("http://localhost:2001", false) + const apiHost = process.env.REACT_APP_BACKEND_API ? process.env.REACT_APP_BACKEND_API : "" + const notebookApi = new NotebookAPI(apiHost, false) + const noteApi = new NoteAPI(apiHost, false) return (