diff --git a/Dockerfile.backend b/Dockerfile.backend new file mode 100644 index 0000000000000000000000000000000000000000..8e43db10addaa6046edddb0c3c8457b86f012cea --- /dev/null +++ b/Dockerfile.backend @@ -0,0 +1,39 @@ +# need node/npm to run "npm run build" for our vue frontend +FROM node:20-alpine as build-frontend + +# working directory for our frontend +WORKDIR /app + +# copying package.json to root folder and installing dependencies +COPY ./frontend/package*.json ./ +RUN npm install + +# copying all of frontend to root folder in container +COPY ./frontend . + +# building frontend +RUN npm run build + +################################################################ +# getting jdk 17 (we use this version in development too) +FROM eclipse-temurin:17-jre-alpine as build-backend + +# working directory for backend +WORKDIR /app + +# copying frontend to static folder so spring can serve it +COPY --from build-frontend /app/dist /app/src/main/resources/static + +# copying backend to root folder in container +COPY . . + +# making maven executable (we had permission issues before adding this) +RUN chmod +x ./mvnw + +# building backend with maven wrapper +RUN ./mvnw clean package -DskipTests + +# exposing port, same port as we used in development +EXPOSE 9876 + +ENTRYPOINT ["java", "-jar", "target/todo-0.0.1-SNAPSHOT.jar"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..e63bd26f6a30f2c089cc616fdc6ebf28baa17be1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,50 @@ +services: + # mongodb stuff + mongodb: + # official mongodb container + image: mongo:latest + # container-name + container_name: mongodb + # env variables + environment: + # creates user with name tododbuser + MONGO_INITDB_ROOT_USERNAME: tododbuser + # sets password for user + MONGO_INITDB_ROOT_PASSWORD: tododbadminpassword + # creates collection/table + MONGO_INITDB_DATABASE: todo + # default mongo port + ports: + - "27017:27017" + # for data persistence, if I understood correctly its like a + # virtual drive for storage of the db between reboots + volumes: + - ./data/db:/data/db + + # backend stuff + backend: + # builds backend from root + build: . + # the internal network our backend will be using + networks: + - todo-network + # mongodb env variables for connection + environment: + MONGO_USER: tododbuser + MONGO_PASSWORD: tododbadminpassword + MONGO_HOST: mongodb + MONGO_PORT: 27017 + MONGO_DB: todo + # same port as we use in our application properties + # and for fetch requests in our frontend + ports: + - "9876:9876" + depends_on: + - mongodb + +# were gonna use this network for both our backend and frontend +networks: + # network name + todo-network: + # default driver I guess? idk, saw it on the official docs + driver: bridge \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 765f795783cfa613bdf02ec28d168183b7d02586..853c00d02ab4c4c88c3bd96af4112d5af9d1ae11 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.application.name=todo server.port=9876 -spring.data.mongodb.uri=mongodb://tododbuser:tododbadminpassword@192.168.179.24:27017/todo +spring.data.mongodb.uri=mongodb://${MONGO_USER}:${MONGO_PASSWORD}@${MONGO_HOST}:${MONGO_PORT}/${MONGO_DB} #openapi setup springdoc.api-docs.path=/v3/api-docs