From 9a1269de6da13576a7ed1df43401558cbc2dd447 Mon Sep 17 00:00:00 2001 From: Selast Lambou Date: Sat, 2 Mar 2024 22:49:52 +0100 Subject: [PATCH] feat: added Dockerfile to the frontend and backend and then configured it --- docker-compose.yaml | 10 +++--- power-pay-backend/.dockerignore | 0 power-pay-backend/Dockerfile | 6 ++++ .../main/resources/application-postgres.yaml | 6 ++++ power-pay-frontend/.dockerignore | 3 ++ power-pay-frontend/Dockerfile | 31 ++++++++++++++++++- power-pay-frontend/nginx/nginx.conf | 8 +++++ 7 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 power-pay-backend/.dockerignore create mode 100644 power-pay-backend/src/main/resources/application-postgres.yaml create mode 100644 power-pay-frontend/.dockerignore create mode 100644 power-pay-frontend/nginx/nginx.conf diff --git a/docker-compose.yaml b/docker-compose.yaml index 2bae19c0..f4bd6c2d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -8,9 +8,11 @@ services: ports: - "8080:8080" depends_on: - - db + - postgres environment: - - DATABASE_URL=postgres://postgres:password@db:5432/postgres + SPRING_DATASOURCE_URL: "jdbc:postgresql://postgres:5432/postgres" + SPRING_DATASOURCE_USERNAME: postgres + SPRING_DATASOURCE_PASSWORD: password postgres: image: postgres @@ -30,14 +32,14 @@ services: ports: - "3000:80" environment: - - REACT_APP_API_URL=http://localhost:3000 + - REACT_APP_BACKEND_URL=http://api:8080 translator: build: context: ./power-pay-translator dockerfile: Dockerfile ports: - - "5000:5000" + - "5001:5000" environment: - BACKEND_API_URL=http://api:8080 diff --git a/power-pay-backend/.dockerignore b/power-pay-backend/.dockerignore new file mode 100644 index 00000000..e69de29b diff --git a/power-pay-backend/Dockerfile b/power-pay-backend/Dockerfile index 255b061c..ccd5137b 100644 --- a/power-pay-backend/Dockerfile +++ b/power-pay-backend/Dockerfile @@ -1 +1,7 @@ FROM eclipse-temurin:17 + +ENV APP_VERSION=0.0.1-SNAPSHOT + +COPY target/power-pay-backend-$APP_VERSION.jar app.jar + +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/power-pay-backend/src/main/resources/application-postgres.yaml b/power-pay-backend/src/main/resources/application-postgres.yaml new file mode 100644 index 00000000..a8ad1600 --- /dev/null +++ b/power-pay-backend/src/main/resources/application-postgres.yaml @@ -0,0 +1,6 @@ +spring: + datasource: + driver-class-name: org.postgresql.Driver + url: jdbc:postgresql://localhost:5432/postgres + username: postgres + password: password diff --git a/power-pay-frontend/.dockerignore b/power-pay-frontend/.dockerignore new file mode 100644 index 00000000..bf8a8e05 --- /dev/null +++ b/power-pay-frontend/.dockerignore @@ -0,0 +1,3 @@ +node_modules +build +npm-debug.log \ No newline at end of file diff --git a/power-pay-frontend/Dockerfile b/power-pay-frontend/Dockerfile index 8bd0a7f1..2a0d88e2 100644 --- a/power-pay-frontend/Dockerfile +++ b/power-pay-frontend/Dockerfile @@ -1 +1,30 @@ -FROM nginx +# Use the official Node.js runtime as the base image +FROM node:18 as build + +# Set the working directory in the container +WORKDIR /app + +# Copy package.json and package-lock.json to the working directory +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy the entire application code to the container +COPY . . + +# Build the React app for production +RUN npm run build + +# Use Nginx as the production server +FROM nginx:stable-alpine + +# Copy the built React app to Nginx's web server directory +COPY --from=build /app/dist /usr/share/nginx/html +COPY --from=build /app/nginx/nginx.conf /etc/nginx/conf.d/default.conf + +# Expose port 80 for the Nginx server +EXPOSE 80 + +# Start Nginx when the container runs +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/power-pay-frontend/nginx/nginx.conf b/power-pay-frontend/nginx/nginx.conf new file mode 100644 index 00000000..c2ef7a49 --- /dev/null +++ b/power-pay-frontend/nginx/nginx.conf @@ -0,0 +1,8 @@ +server { + listen 80; + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html =404; + } +} \ No newline at end of file