diff --git a/.github/file-filters.yml b/.github/file-filters.yml index 498232b29..c5abf8722 100644 --- a/.github/file-filters.yml +++ b/.github/file-filters.yml @@ -13,6 +13,10 @@ presenter-test-unit-code: &presenter-test-unit-code presenter-test-build-code: &presenter-test-build-code - 'presenter/**/*' +presenter-test-build-docker: &presenter-test-build-docker + - 'presenter/**/*' + + presenter-test-build-docs: &presenter-test-build-docs - 'presenter/**/*.md' - 'presenter/.vuepress/*' @@ -30,6 +34,9 @@ backend-test-unit-code: &backend-test-unit-code backend-test-build-code: &backend-test-build-code - 'backend/**/*' +backend-test-build-docker: &backend-test-build-docker + - 'backend/**/*' + backend-test-build-docs: &backend-test-build-docs - 'backend/**/*.md' - 'backend/.vuepress/*' \ No newline at end of file diff --git a/.github/workflows/backend.test.build.docker.yml b/.github/workflows/backend.test.build.docker.yml new file mode 100644 index 000000000..0ae68a629 --- /dev/null +++ b/.github/workflows/backend.test.build.docker.yml @@ -0,0 +1,52 @@ +name: "backend:test:build test docker" + +on: push + +jobs: + # only (but most important) job from this workflow required for pull requests + # check results serve as run conditions for all other jobs here + files-changed: + name: Detect File Changes - backend-test-build-docker + runs-on: ubuntu-latest + outputs: + changes: ${{ steps.changes.outputs.backend-test-build-docker }} + steps: + - uses: actions/checkout@v4 + + - name: Check for backend file changes + uses: dorny/paths-filter@v3.0.1 + id: changes + with: + token: ${{ github.token }} + filters: .github/file-filters.yml + list-files: shell + + build-production: + if: needs.files-changed.outputs.changes == 'true' + name: Build Docker Production - Backend + needs: files-changed + runs-on: ubuntu-latest + env: + WORKING_DIRECTORY: ./backend + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Backend | Build Docker Production + run: docker compose -f docker-compose.yml build + working-directory: ${{env.WORKING_DIRECTORY}} + + build-development: + if: needs.files-changed.outputs.changes == 'true' + name: Build Docker Development - Backend + needs: files-changed + runs-on: ubuntu-latest + env: + WORKING_DIRECTORY: ./backend + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Backend | Build Docker Development + run: docker compose build + working-directory: ${{env.WORKING_DIRECTORY}} \ No newline at end of file diff --git a/.github/workflows/backend.test.unit.code.yml b/.github/workflows/backend.test.unit.code.yml index e2436e73b..c04c5f14b 100644 --- a/.github/workflows/backend.test.unit.code.yml +++ b/.github/workflows/backend.test.unit.code.yml @@ -36,7 +36,7 @@ jobs: uses: actions/checkout@v4 - name: Backend | docker-compose database - run: docker-compose -f docker-compose.yml -f docker-compose.test.yml up --detach --no-deps database + run: docker-compose -f docker-compose.yml up --detach --no-deps database - name: Backend | Unit run: npm install && npm run db:migrate && npm run test:unit diff --git a/.github/workflows/presenter.test.build.docker.yml b/.github/workflows/presenter.test.build.docker.yml new file mode 100644 index 000000000..15e8cecd7 --- /dev/null +++ b/.github/workflows/presenter.test.build.docker.yml @@ -0,0 +1,52 @@ +name: "presenter:test:build test docker" + +on: push + +jobs: + # only (but most important) job from this workflow required for pull requests + # check results serve as run conditions for all other jobs here + files-changed: + name: Detect File Changes - presenter-test-build-docker + runs-on: ubuntu-latest + outputs: + changes: ${{ steps.changes.outputs.presenter-test-build-docker }} + steps: + - uses: actions/checkout@v4 + + - name: Check for presenter file changes + uses: dorny/paths-filter@v3.0.1 + id: changes + with: + token: ${{ github.token }} + filters: .github/file-filters.yml + list-files: shell + + build-production: + if: needs.files-changed.outputs.changes == 'true' + name: Build Docker Production - Presenter + needs: files-changed + runs-on: ubuntu-latest + env: + WORKING_DIRECTORY: ./presenter + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Presenter | Build Docker Production + run: docker compose -f docker-compose.yml build + working-directory: ${{env.WORKING_DIRECTORY}} + + build-development: + if: needs.files-changed.outputs.changes == 'true' + name: Build Docker Development - Presenter + needs: files-changed + runs-on: ubuntu-latest + env: + WORKING_DIRECTORY: ./presenter + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Presenter | Build Docker Development + run: docker compose build + working-directory: ${{env.WORKING_DIRECTORY}} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..e55f99e97 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,53 @@ +FROM node:21-alpine3.17 as base + +# ENVs (available in production aswell, can be overwritten by commandline or env file) +## DOCKER_WORKDIR would be a classical ARG, but that is not multi layer persistent - shame +ENV DOCKER_WORKDIR="/app" +## We Cannot do `$(date -u +'%Y-%m-%dT%H:%M:%SZ')` here so we use unix timestamp=0 +ENV BUILD_DATE="1970-01-01T00:00:00.00Z" +## We cannot do $(npm run version).${BUILD_NUMBER} here so we default to 0.0.0.0 +ENV BUILD_VERSION="0.0.0.0" +## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000 +ENV BUILD_COMMIT="0000000" +## SET NODE_ENV +ENV NODE_ENV="production" +## App relevant Envs +ENV PORT="3000" + +# Labels +LABEL org.label-schema.build-date="${BUILD_DATE}" +LABEL org.label-schema.name="dreammall" +LABEL org.label-schema.description="DreamMall" +LABEL org.label-schema.usage="https://github.com/dreammall-earth/dreammall.earth/blob/master/README.md" +LABEL org.label-schema.url="https://github.com/dreammall-earth/dreammall.earth/" +LABEL org.label-schema.vcs-url="https://github.com/dreammall-earth/dreammall.earth/tree/master/" +LABEL org.label-schema.vcs-ref="${BUILD_COMMIT}" +LABEL org.label-schema.vendor="DreamMall" +LABEL org.label-schema.version="${BUILD_VERSION}" +LABEL org.label-schema.schema-version="1.0" +LABEL maintainer="info@it4c.dev" + +# Install Additional Software +## install: node-gyp dependencies +# RUN apk --no-cache add g++ make python3 + +# Settings +## Expose Container Port +EXPOSE ${PORT} + +## Workdir +RUN mkdir -p ${DOCKER_WORKDIR} +WORKDIR ${DOCKER_WORKDIR} + +################################################################################## +# DOCUMENTATION ################################################################## +################################################################################## +FROM base as documentation + +# We don't need to copy or build anything since we gonna bind to the +# local filesystem which will need a rebuild anyway + +# Run command +# (for development we need to execute npm install since the +# node_modules are on another volume and need updating) +CMD /bin/sh -c "npm install && npm run docs:dev" diff --git a/README.md b/README.md index e84eebaa4..376536af6 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,20 @@ The following commands are available: | **Maintenance** | | | `npm run update` | Check for updates | +## Docker + +The following endpoints are provided if `docker compose` is used: + +| Endpoint | Description | +|----------------------------------------------------------------------|----------------------------| +| [http://localhost:3306](http://localhost:3306) | MySQL Database | +| [http://localhost:4000/graphql](http://localhost:4000/graphql) | Backend GraphQL API | +| [http://localhost:4000/playground](http://localhost:4000/playground) | Backend GraphQL Playground | +| [http://localhost:3000](http://localhost:3000) | Presenter Frontend | +| [http://localhost:8081](http://localhost:8081) | Presenter Documentation | +| [http://localhost:6006](http://localhost:6006) | Presenter Storybook | +| [http://localhost:8080](http://localhost:8080) | Documentation | + ## How to release Generate a new version using `npm version --git-tag-version=false patch|minor|major`. diff --git a/backend/.vuepress/assets/dreammall-logo.svg b/backend/.vuepress/assets/dreammall-logo.svg new file mode 100644 index 000000000..0be57a847 --- /dev/null +++ b/backend/.vuepress/assets/dreammall-logo.svg @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/backend/README.md b/backend/README.md index 6aa913bbd..41304f13e 100644 --- a/backend/README.md +++ b/backend/README.md @@ -13,7 +13,7 @@ The Dreammall backend. -![](../presenter/src/assets/dreammall-logo.svg) +![](.vuepress/assets/dreammall-logo.svg) ## Requirements & Technology diff --git a/docker-compose.override.yml b/docker-compose.override.yml index e13884a97..a76e3ce02 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -1,11 +1,135 @@ version: "3.4" services: - - ######################################################### - ## MARIADB ############################################## - ######################################################### + ######################################################## + # DATABASE ############################################# + ######################################################## database: networks: - internal-net - external-net + + ######################################################## + # PRESENTER ############################################ + ######################################################## + presenter: + # name the image so that it cannot be found in a DockerHub repository, otherwise it will not be built locally from the 'dockerfile' but pulled from there + image: dreammall/presenter:local-development + build: + target: development + ports: + # development server port + - 24678:24678 + environment: + - NODE_ENV=development + volumes: + # This makes sure the docker container has its own node modules. + # Therefore it is possible to have a different node version on the host machine + #- presenter_node_modules:/app/node_modules + # bind the local folder to the docker to allow live reload + - ./presenter:/app + + ####################################################### + # PRESENTER STORYBOOK ################################# + ####################################################### + presenter-storybook: + # name the image so that it cannot be found in a DockerHub repository, otherwise it will not be built locally from the 'dockerfile' but pulled from there + image: dreammall/presenter:local-storybook + build: + context: ./presenter + target: storybook + ports: + - 6006:6006 + environment: + - NODE_ENV=development + volumes: + # This makes sure the docker container has its own node modules. + # Therefore it is possible to have a different node version on the host machine + #- presenter_storybook_node_modules:/app/node_modules + # bind the local folder to the docker to allow live reload + - ./presenter:/app + + ####################################################### + # PRESENTER DOCUMENTATION ############################# + ####################################################### + presenter-documentation: + # name the image so that it cannot be found in a DockerHub repository, otherwise it will not be built locally from the 'dockerfile' but pulled from there + image: dreammall/presenter:local-documentation + build: + context: ./presenter + target: documentation + ports: + - 8081:8080 + environment: + - NODE_ENV=development + volumes: + # This makes sure the docker container has its own node modules. + # Therefore it is possible to have a different node version on the host machine + #- presenter_documentation_node_modules:/app/node_modules + # bind the local folder to the docker to allow live reload + - ./presenter:/app + + ####################################################### + # BACKEND ############################################# + ####################################################### + backend: + # name the image so that it cannot be found in a DockerHub repository, otherwise it will not be built locally from the 'dockerfile' but pulled from there + image: dreammall/backend:local-development + build: + context: ./backend + target: development + environment: + - NODE_ENV=development + volumes: + # This makes sure the docker container has its own node modules. + # Therefore it is possible to have a different node version on the host machine + #- backend_node_modules:/server/node_modules + # bind the local folder to the docker to allow live reload + - ./backend:/server + + ####################################################### + # BACKEND DOCUMENTATION ############################### + ####################################################### + backend-documentation: + # name the image so that it cannot be found in a DockerHub repository, otherwise it will not be built locally from the 'dockerfile' but pulled from there + image: dreammall/backend:local-documentation + build: + context: ./backend + target: documentation + ports: + - 8082:8080 + environment: + - NODE_ENV=development + volumes: + # This makes sure the docker container has its own node modules. + # Therefore it is possible to have a different node version on the host machine + #- backend_documentation_node_modules:/app/node_modules + # bind the local folder to the docker to allow live reload + - ./backend:/server + + ######################################################## + # DOCUMENTATION ######################################## + ######################################################## + documentation: + # name the image so that it cannot be found in a DockerHub repository, otherwise it will not be built locally from the 'dockerfile' but pulled from there + image: dreammall/dreammall:local-documentation + build: + target: documentation + ports: + - 8080:8080 + environment: + - NODE_ENV=development + volumes: + # This makes sure the docker container has its own node modules. + # Therefore it is possible to have a different node version on the host machine + #- documentation_node_modules:/app/node_modules + # bind the local folder to the docker to allow live reload + - ./:/app + +volumes: + presenter_node_modules: + presenter_storybook_node_modules: + presenter_documentation_node_modules: + backend_node_modules: + backend_documentation_node_modules: + documentation_node_modules: \ No newline at end of file diff --git a/docker-compose.test.yml b/docker-compose.test.yml deleted file mode 100644 index 53cdc359a..000000000 --- a/docker-compose.test.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: "3.4" - -services: - ######################################################### - ## MARIADB ############################################## - ######################################################### - database: - image: dreammall.earth/database:test - networks: - - internal-net - - external-net - volumes: - - db_test_vol:/var/lib/mysql - -networks: - external-net: - internal-net: - internal: true - -volumes: - db_test_vol: - diff --git a/docker-compose.yml b/docker-compose.yml index bed27a62d..2640ce98d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,9 @@ version: "3.4" services: - - ######################################################### - ## MARIADB ############################################## - ######################################################### + ######################################################## + # DATABASE ############################################# + ######################################################## database: build: context: ./database @@ -15,11 +14,49 @@ services: - MARIADB_USER=root networks: - internal-net + - external-net ports: - 3306:3306 volumes: - db_vol:/var/lib/mysql + ######################################################## + # PRESENTER ############################################ + ######################################################## + presenter: + # name the image so that it cannot be found in a DockerHub repository, otherwise it will not be built locally from the 'dockerfile' but pulled from there + image: dreammall/presenter:local-production + build: + context: ./presenter + target: production + networks: + - external-net + - internal-net + ports: + - 3000:3000 + environment: + - NODE_ENV=production + + ####################################################### + # BACKEND ############################################# + ####################################################### + backend: + # name the image so that it cannot be found in a DockerHub repository, otherwise it will not be built locally from the 'dockerfile' but pulled from there + image: it4c/backend:local-production + build: + context: ./backend + target: production + depends_on: + - database + networks: + - external-net + - internal-net + ports: + - 4000:4000 + environment: + - DATABASE_URL=mysql://root:@database:3306/dreammall.earth + - NODE_ENV=production + networks: external-net: internal-net: @@ -27,3 +64,5 @@ networks: volumes: db_vol: + frontend_node_modules: + backend_node_modules: