From 2c5d780db4d651df679d485c1dbbee8662b5b8fa Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 24 Jun 2021 22:23:15 +0200 Subject: [PATCH] docker-compose github workflows publish & lint --- .github/workflows/publish.yml | 52 +++++++++++++++++++++++++++++++-- .github/workflows/test.yml | 55 +++++++++++++++++++++++++++++++++++ docker-compose.override.yml | 21 ++++++++++++- docker-compose.yml | 26 ++++++++++++++++- 4 files changed, 149 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 66bc2bbf8..8161fb3b4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -7,7 +7,7 @@ on: jobs: ############################################################################## - # JOB: DOCKER BUILD COMMUNITY NEO4J ########################################## + # JOB: DOCKER BUILD PRODUCTION FRONTEND ###################################### ############################################################################## build_production_frontend: name: Docker Build Production - Frontend @@ -43,6 +43,43 @@ jobs: name: docker-frontend-production path: /tmp/frontend.tar + ############################################################################## + # JOB: DOCKER BUILD PRODUCTION BACKEND ####################################### + ############################################################################## + build_production_backend: + name: Docker Build Production - Backend + runs-on: ubuntu-latest + #needs: [nothing] + steps: + ########################################################################## + # CHECKOUT CODE ########################################################## + ########################################################################## + - name: Checkout code + uses: actions/checkout@v2 + ########################################################################## + # SET ENVS ############################################################### + ########################################################################## + - name: ENV - VERSION + run: echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV + - name: ENV - BUILD_DATE + run: echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV + - name: ENV - BUILD_VERSION + run: echo "BUILD_VERSION=${VERSION}.${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV + - name: ENV - BUILD_COMMIT + run: echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV + ########################################################################## + # BACKEND ################################################################ + ########################################################################## + - name: Backend | Build `production` image + run: | + docker build --target production -t "gradido/backend:latest" -t "gradido/backend:production" -t "gradido/backend:${VERSION}" -t "gradido/backend:${BUILD_VERSION}" backend/ + docker save "gradido/backend" > /tmp/backend.tar + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: docker-backend-production + path: /tmp/backend.tar + ############################################################################## # JOB: DOCKER BUILD PRODUCTION LOGIN SERVER ################################## ############################################################################## @@ -199,7 +236,7 @@ jobs: upload_to_dockerhub: name: Upload to Dockerhub runs-on: ubuntu-latest - needs: [build_production_frontend, build_production_login_server, build_production_community_server, build_production_mariadb, build_production_nginx] + needs: [build_production_frontend, build_production_backend, build_production_login_server, build_production_community_server, build_production_mariadb, build_production_nginx] env: DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} @@ -212,13 +249,20 @@ jobs: ########################################################################## # DOWNLOAD DOCKER IMAGES ################################################# ########################################################################## - - name: Download Docker Image (Neo4J) + - name: Download Docker Image (Frontend) uses: actions/download-artifact@v2 with: name: docker-frontend-production path: /tmp - name: Load Docker Image run: docker load < /tmp/frontend.tar + - name: Download Docker Image (Backend) + uses: actions/download-artifact@v2 + with: + name: docker-backend-production + path: /tmp + - name: Load Docker Image + run: docker load < /tmp/backend.tar - name: Download Docker Image (Login Server) uses: actions/download-artifact@v2 with: @@ -254,6 +298,8 @@ jobs: run: echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin - name: Push frontend run: docker push --all-tags gradido/frontend + - name: Push backend + run: docker push --all-tags gradido/backend - name: Push login_server run: docker push --all-tags gradido/login_server - name: Push community_server diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 002118f5b..8f7c2db05 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,6 +30,32 @@ jobs: name: docker-frontend-test path: /tmp/frontend.tar + ############################################################################## + # JOB: DOCKER BUILD TEST BACKEND ############################################# + ############################################################################## + build_test_backend: + name: Docker Build Test - Backend + runs-on: ubuntu-latest + #needs: [nothing] + steps: + ########################################################################## + # CHECKOUT CODE ########################################################## + ########################################################################## + - name: Checkout code + uses: actions/checkout@v2 + ########################################################################## + # FRONTEND ############################################################### + ########################################################################## + - name: Backend | Build `test` image + run: | + docker build --target test -t "gradido/backend:test" backend/ + docker save "gradido/backend:test" > /tmp/backend.tar + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: docker-backend-test + path: /tmp/backend.tar + ############################################################################## # JOB: DOCKER BUILD TEST LOGIN SERVER ######################################## ############################################################################## @@ -159,6 +185,35 @@ jobs: - name: frontend | Lint run: docker run --rm gradido/frontend:test yarn run lint + ############################################################################## + # JOB: LINT BACKEND ######################################################### + ############################################################################## + lint_backend: + name: Lint - Backend + runs-on: ubuntu-latest + needs: [build_test_backend] + steps: + ########################################################################## + # CHECKOUT CODE ########################################################## + ########################################################################## + - name: Checkout code + uses: actions/checkout@v2 + ########################################################################## + # DOWNLOAD DOCKER IMAGE ################################################## + ########################################################################## + - name: Download Docker Image (Backend) + uses: actions/download-artifact@v2 + with: + name: docker-backend-test + path: /tmp + - name: Load Docker Image + run: docker load < /tmp/backend.tar + ########################################################################## + # LINT FRONTEND ########################################################### + ########################################################################## + - name: backend | Lint + run: docker run --rm gradido/backend:test yarn run lint + ############################################################################## # JOB: UNIT TEST FRONTEND ################################################### ############################################################################## diff --git a/docker-compose.override.yml b/docker-compose.override.yml index cbb041457..092cd9db1 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -21,6 +21,24 @@ services: # bind the local folder to the docker to allow live reload - ./frontend:/app + ######################################################## + # BACKEND ############################################## + ######################################################## + backend: + image: gradido/backend:development + build: + target: development + networks: + - external-net + 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:/app/node_modules + # bind the local folder to the docker to allow live reload + - ./backend:/app + ######################################################### ## LOGIN SERVER ######################################### ######################################################### @@ -99,4 +117,5 @@ services: volumes: frontend_node_modules: - login_build_ubuntu_3.1: + backend_node_modules: + login_build_ubuntu_3.1: \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 35e015f4e..7528527e6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -47,7 +47,31 @@ services: ports: - 3306:3306 volumes: - - db_vol:/var/lib/mysql + - db_vol:/var/lib/mysql + + ######################################################## + # BACKEND ############################################## + ######################################################## + backend: + image: gradido/backend:latest + build: + context: ./backend + target: production + networks: + - internal-net + ports: + - 4000:4000 + environment: + # Envs used in Dockerfile + # - DOCKER_WORKDIR="/app" + # - PORT=4000 + - BUILD_DATE + - BUILD_VERSION + - BUILD_COMMIT + - NODE_ENV="production" + # Application only envs + #env_file: + # - ./frontend/.env ######################################################### ## LOGIN SERVER #########################################