From d354f9630a7f4dc7b14c0a1bd66f802f48d94182 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 12:44:01 +0200 Subject: [PATCH 01/15] Use build args instead of envs for the version, date & commit --- .github/workflows/publish.yml | 302 +++++++++++++++++++--------------- backend/Dockerfile | 7 +- neo4j/Dockerfile | 6 +- webapp/Dockerfile | 6 +- 4 files changed, 176 insertions(+), 145 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 24350a81a..701c12aa1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,8 +2,8 @@ name: ocelot.social publish CI on: push: - branches: - - master +# branches: +# - master jobs: ############################################################################## @@ -56,7 +56,16 @@ jobs: ########################################################################## - name: Neo4J | Build `community` image run: | - docker build --target community -t "ocelotsocialnetwork/neo4j:latest" -t "ocelotsocialnetwork/neo4j:community" -t "ocelotsocialnetwork/neo4j:${VERSION}" -t "ocelotsocialnetwork/neo4j:${BUILD_VERSION}" neo4j/ + docker build \ + --target community \ + -t "ocelotsocialnetwork/neo4j:latest" \ + -t "ocelotsocialnetwork/neo4j:community" \ + -t "ocelotsocialnetwork/neo4j:${VERSION}" \ + -t "ocelotsocialnetwork/neo4j:${BUILD_VERSION}" \ + --build-arg BUILD_DATE=$BUILD_ DATE \ + --build-arg BUILD_VERSION=$BUILD_VERSION \ + --build-arg BUILD_COMMIT=$BUILD_COMMIT \ + neo4j/ docker save "ocelotsocialnetwork/neo4j" > /tmp/neo4j.tar - name: Upload Artifact uses: actions/upload-artifact@v2 @@ -93,7 +102,15 @@ jobs: ########################################################################## - name: backend | Build `production` image run: | - docker build --target production -t "ocelotsocialnetwork/backend:latest" -t "ocelotsocialnetwork/backend:${VERSION}" -t "ocelotsocialnetwork/backend:${BUILD_VERSION}" backend/ + docker build \ + --target production \ + -t "ocelotsocialnetwork/backend:latest" \ + -t "ocelotsocialnetwork/backend:${VERSION}" \ + -t "ocelotsocialnetwork/backend:${BUILD_VERSION}" + --build-arg BUILD_DATE=$BUILD_ DATE \ + --build-arg BUILD_VERSION=$BUILD_VERSION \ + --build-arg BUILD_COMMIT=$BUILD_COMMIT \ + backend/ docker save "ocelotsocialnetwork/backend" > /tmp/backend.tar - name: Upload Artifact uses: actions/upload-artifact@v2 @@ -130,7 +147,15 @@ jobs: ########################################################################## - name: webapp | Build `production` image run: | - docker build --target production -t "ocelotsocialnetwork/webapp:latest" -t "ocelotsocialnetwork/webapp:${VERSION}" -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}" webapp/ + docker build \ + --target production \ + -t "ocelotsocialnetwork/webapp:latest" \ + -t "ocelotsocialnetwork/webapp:${VERSION}" \ + -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}" \ + --build-arg BUILD_DATE=$BUILD_ DATE \ + --build-arg BUILD_VERSION=$BUILD_VERSION \ + --build-arg BUILD_COMMIT=$BUILD_COMMIT \ + webapp/ docker save "ocelotsocialnetwork/webapp" > /tmp/webapp.tar - name: Upload Artifact uses: actions/upload-artifact@v2 @@ -168,7 +193,14 @@ jobs: - name: maintenance | Build `production` image # TODO: --target production run: | - docker build -t "ocelotsocialnetwork/maintenance:latest" -t "ocelotsocialnetwork/maintenance:${VERSION}" -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" webapp/ -f webapp/Dockerfile.maintenance + docker build \ + -t "ocelotsocialnetwork/maintenance:latest" \ + -t "ocelotsocialnetwork/maintenance:${VERSION}" \ + -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" \ + --build-arg BUILD_DATE=$BUILD_ DATE \ + --build-arg BUILD_VERSION=$BUILD_VERSION \ + --build-arg BUILD_COMMIT=$BUILD_COMMIT \ + webapp/ -f webapp/Dockerfile.maintenance docker save "ocelotsocialnetwork/maintenance" > /tmp/maintenance.tar - name: Upload Artifact uses: actions/upload-artifact@v2 @@ -176,132 +208,132 @@ jobs: name: docker-maintenance-production path: /tmp/maintenance.tar - ############################################################################## - # JOB: UPLOAD TO DOCKERHUB ################################################### - ############################################################################## - upload_to_dockerhub: - name: Upload to Dockerhub - runs-on: ubuntu-latest - needs: [build_production_neo4j,build_production_backend,build_production_webapp,build_production_maintenance] - env: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v2 - ########################################################################## - # DOWNLOAD DOCKER IMAGES ################################################# - ########################################################################## - - name: Download Docker Image (Neo4J) - uses: actions/download-artifact@v2 - with: - name: docker-neo4j-community - path: /tmp - - name: Load Docker Image - run: docker load < /tmp/neo4j.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 (WebApp) - uses: actions/download-artifact@v2 - with: - name: docker-webapp-production - path: /tmp - - name: Load Docker Image - run: docker load < /tmp/webapp.tar - - name: Download Docker Image (Maintenance) - uses: actions/download-artifact@v2 - with: - name: docker-maintenance-production - path: /tmp - - name: Load Docker Image - run: docker load < /tmp/maintenance.tar - ########################################################################## - # Upload ################################################################# - ########################################################################## - - name: login to dockerhub - run: echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin - - name: Push neo4j - run: docker push --all-tags ocelotsocialnetwork/neo4j - - name: Push backend - run: docker push --all-tags ocelotsocialnetwork/backend - - name: Push webapp - run: docker push --all-tags ocelotsocialnetwork/webapp - - name: Push maintenance - run: docker push --all-tags ocelotsocialnetwork/maintenance - - ############################################################################## - # JOB: GITHUB TAG LATEST VERSION ############################################# - ############################################################################## - github_tag: - name: Tag latest version on Github - runs-on: ubuntu-latest - needs: [upload_to_dockerhub] - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch full History for changelog - ########################################################################## - # 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 - ########################################################################## - # Push version tag to GitHub ############################################# - ########################################################################## - # TODO: this will error on duplicate - #- name: package-version-to-git-tag - # uses: pkgdeps/git-tag-action@v2 - # with: - # github_token: ${{ secrets.GITHUB_TOKEN }} - # github_repo: ${{ github.repository }} - # version: ${{ env.VERSION }} - # git_commit_sha: ${{ github.sha }} - # git_tag_prefix: "v" - ########################################################################## - # Push build tag to GitHub ############################################### - ########################################################################## - - name: package-version-to-git-tag + build number - uses: pkgdeps/git-tag-action@v2 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - github_repo: ${{ github.repository }} - version: ${{ env.BUILD_VERSION }} - git_commit_sha: ${{ github.sha }} - git_tag_prefix: "b" - ########################################################################## - # Push release tag to GitHub ############################################# - ########################################################################## - - name: yarn install - run: yarn install - - name: generate changelog - run: yarn auto-changelog --latest-version ${{ env.VERSION }} --unreleased-only - - name: package-version-to-git-release - continue-on-error: true # Will fail if tag exists - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token - with: - tag_name: ${{ env.VERSION }} - release_name: ${{ env.VERSION }} - body_path: ./CHANGELOG.md - draft: false - prerelease: false \ No newline at end of file +# ############################################################################## +# # JOB: UPLOAD TO DOCKERHUB ################################################### +# ############################################################################## +# upload_to_dockerhub: +# name: Upload to Dockerhub +# runs-on: ubuntu-latest +# needs: [build_production_neo4j,build_production_backend,build_production_webapp,build_production_maintenance] +# env: +# DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} +# DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} +# steps: +# ########################################################################## +# # CHECKOUT CODE ########################################################## +# ########################################################################## +# - name: Checkout code +# uses: actions/checkout@v2 +# ########################################################################## +# # DOWNLOAD DOCKER IMAGES ################################################# +# ########################################################################## +# - name: Download Docker Image (Neo4J) +# uses: actions/download-artifact@v2 +# with: +# name: docker-neo4j-community +# path: /tmp +# - name: Load Docker Image +# run: docker load < /tmp/neo4j.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 (WebApp) +# uses: actions/download-artifact@v2 +# with: +# name: docker-webapp-production +# path: /tmp +# - name: Load Docker Image +# run: docker load < /tmp/webapp.tar +# - name: Download Docker Image (Maintenance) +# uses: actions/download-artifact@v2 +# with: +# name: docker-maintenance-production +# path: /tmp +# - name: Load Docker Image +# run: docker load < /tmp/maintenance.tar +# ########################################################################## +# # Upload ################################################################# +# ########################################################################## +# - name: login to dockerhub +# run: echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin +# - name: Push neo4j +# run: docker push --all-tags ocelotsocialnetwork/neo4j +# - name: Push backend +# run: docker push --all-tags ocelotsocialnetwork/backend +# - name: Push webapp +# run: docker push --all-tags ocelotsocialnetwork/webapp +# - name: Push maintenance +# run: docker push --all-tags ocelotsocialnetwork/maintenance +# +# ############################################################################## +# # JOB: GITHUB TAG LATEST VERSION ############################################# +# ############################################################################## +# github_tag: +# name: Tag latest version on Github +# runs-on: ubuntu-latest +# needs: [upload_to_dockerhub] +# steps: +# ########################################################################## +# # CHECKOUT CODE ########################################################## +# ########################################################################## +# - name: Checkout code +# uses: actions/checkout@v2 +# with: +# fetch-depth: 0 # Fetch full History for changelog +# ########################################################################## +# # 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 +# ########################################################################## +# # Push version tag to GitHub ############################################# +# ########################################################################## +# # TODO: this will error on duplicate +# #- name: package-version-to-git-tag +# # uses: pkgdeps/git-tag-action@v2 +# # with: +# # github_token: ${{ secrets.GITHUB_TOKEN }} +# # github_repo: ${{ github.repository }} +# # version: ${{ env.VERSION }} +# # git_commit_sha: ${{ github.sha }} +# # git_tag_prefix: "v" +# ########################################################################## +# # Push build tag to GitHub ############################################### +# ########################################################################## +# - name: package-version-to-git-tag + build number +# uses: pkgdeps/git-tag-action@v2 +# with: +# github_token: ${{ secrets.GITHUB_TOKEN }} +# github_repo: ${{ github.repository }} +# version: ${{ env.BUILD_VERSION }} +# git_commit_sha: ${{ github.sha }} +# git_tag_prefix: "b" +# ########################################################################## +# # Push release tag to GitHub ############################################# +# ########################################################################## +# - name: yarn install +# run: yarn install +# - name: generate changelog +# run: yarn auto-changelog --latest-version ${{ env.VERSION }} --unreleased-only +# - name: package-version-to-git-release +# continue-on-error: true # Will fail if tag exists +# id: create_release +# uses: actions/create-release@v1 +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token +# with: +# tag_name: ${{ env.VERSION }} +# release_name: ${{ env.VERSION }} +# body_path: ./CHANGELOG.md +# draft: false +# prerelease: false \ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile index 2f2b70f04..146e1151a 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -3,15 +3,14 @@ ################################################################################## FROM node:12.19.0-alpine3.10 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" +ARG BUILD_DATE="1970-01-01T00:00:00.00Z" ## We cannot do $(yarn run version)-${BUILD_NUMBER} here so we default to 0.0.0-0 -ENV BUILD_VERSION="0.0.0-0" +ARG BUILD_VERSION="0.0.0-0" ## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000 -ENV BUILD_COMMIT="0000000" +ARG BUILD_COMMIT="0000000" ## SET NODE_ENV ENV NODE_ENV="production" ## App relevant Envs diff --git a/neo4j/Dockerfile b/neo4j/Dockerfile index e7931378a..79c4fb303 100644 --- a/neo4j/Dockerfile +++ b/neo4j/Dockerfile @@ -5,11 +5,11 @@ FROM neo4j:3.5.14 as community # ENVs (available in production aswell, can be overwritten by commandline or env file) ## 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" +ARG BUILD_DATE="1970-01-01T00:00:00.00Z" ## We cannot do $(yarn run version)-${BUILD_NUMBER} here so we default to 0.0.0-0 -ENV BUILD_VERSION="0.0.0-0" +ARG BUILD_VERSION="0.0.0-0" ## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000 -ENV BUILD_COMMIT="0000000" +ARG BUILD_COMMIT="0000000" # Labels LABEL org.label-schema.build-date="${BUILD_DATE}" diff --git a/webapp/Dockerfile b/webapp/Dockerfile index eda437920..f4e96e202 100644 --- a/webapp/Dockerfile +++ b/webapp/Dockerfile @@ -7,11 +7,11 @@ FROM node:12.19.0-alpine3.10 as base ## 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" +ARG BUILD_DATE="1970-01-01T00:00:00.00Z" ## We cannot do $(yarn run version)-${BUILD_NUMBER} here so we default to 0.0.0-0 -ENV BUILD_VERSION="0.0.0-0" +ARG BUILD_VERSION="0.0.0-0" ## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000 -ENV BUILD_COMMIT="0000000" +ARG BUILD_COMMIT="0000000" ## SET NODE_ENV ENV NODE_ENV="production" ## App relevant Envs From 31aff904f8655141b1fdcd980c3aa90f8c8ee9da Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 12:51:44 +0200 Subject: [PATCH 02/15] multiline not properly working --- .github/workflows/publish.yml | 40 ++++------------------------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 701c12aa1..e0b9d0852 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -56,16 +56,7 @@ jobs: ########################################################################## - name: Neo4J | Build `community` image run: | - docker build \ - --target community \ - -t "ocelotsocialnetwork/neo4j:latest" \ - -t "ocelotsocialnetwork/neo4j:community" \ - -t "ocelotsocialnetwork/neo4j:${VERSION}" \ - -t "ocelotsocialnetwork/neo4j:${BUILD_VERSION}" \ - --build-arg BUILD_DATE=$BUILD_ DATE \ - --build-arg BUILD_VERSION=$BUILD_VERSION \ - --build-arg BUILD_COMMIT=$BUILD_COMMIT \ - neo4j/ + docker build --target community -t "ocelotsocialnetwork/neo4j:latest" -t "ocelotsocialnetwork/neo4j:community" -t "ocelotsocialnetwork/neo4j:${VERSION}" -t "ocelotsocialnetwork/neo4j:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_ DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT neo4j/ docker save "ocelotsocialnetwork/neo4j" > /tmp/neo4j.tar - name: Upload Artifact uses: actions/upload-artifact@v2 @@ -102,15 +93,7 @@ jobs: ########################################################################## - name: backend | Build `production` image run: | - docker build \ - --target production \ - -t "ocelotsocialnetwork/backend:latest" \ - -t "ocelotsocialnetwork/backend:${VERSION}" \ - -t "ocelotsocialnetwork/backend:${BUILD_VERSION}" - --build-arg BUILD_DATE=$BUILD_ DATE \ - --build-arg BUILD_VERSION=$BUILD_VERSION \ - --build-arg BUILD_COMMIT=$BUILD_COMMIT \ - backend/ + docker build --target production -t "ocelotsocialnetwork/backend:latest" -t "ocelotsocialnetwork/backend:${VERSION}" -t "ocelotsocialnetwork/backend:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_ DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT backend/ docker save "ocelotsocialnetwork/backend" > /tmp/backend.tar - name: Upload Artifact uses: actions/upload-artifact@v2 @@ -147,15 +130,7 @@ jobs: ########################################################################## - name: webapp | Build `production` image run: | - docker build \ - --target production \ - -t "ocelotsocialnetwork/webapp:latest" \ - -t "ocelotsocialnetwork/webapp:${VERSION}" \ - -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}" \ - --build-arg BUILD_DATE=$BUILD_ DATE \ - --build-arg BUILD_VERSION=$BUILD_VERSION \ - --build-arg BUILD_COMMIT=$BUILD_COMMIT \ - webapp/ + docker build --target production -t "ocelotsocialnetwork/webapp:latest" -t "ocelotsocialnetwork/webapp:${VERSION}" -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_ DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT webapp/ docker save "ocelotsocialnetwork/webapp" > /tmp/webapp.tar - name: Upload Artifact uses: actions/upload-artifact@v2 @@ -193,14 +168,7 @@ jobs: - name: maintenance | Build `production` image # TODO: --target production run: | - docker build \ - -t "ocelotsocialnetwork/maintenance:latest" \ - -t "ocelotsocialnetwork/maintenance:${VERSION}" \ - -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" \ - --build-arg BUILD_DATE=$BUILD_ DATE \ - --build-arg BUILD_VERSION=$BUILD_VERSION \ - --build-arg BUILD_COMMIT=$BUILD_COMMIT \ - webapp/ -f webapp/Dockerfile.maintenance + docker build -t "ocelotsocialnetwork/maintenance:latest" -t "ocelotsocialnetwork/maintenance:${VERSION}" -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_ DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT webapp/ -f webapp/Dockerfile.maintenance docker save "ocelotsocialnetwork/maintenance" > /tmp/maintenance.tar - name: Upload Artifact uses: actions/upload-artifact@v2 From 6d890e28ae554d43bc849356ded83d7d5d8c9d1b Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 12:59:14 +0200 Subject: [PATCH 03/15] fixed build command --- .github/workflows/publish.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e0b9d0852..666266e39 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -56,7 +56,7 @@ jobs: ########################################################################## - name: Neo4J | Build `community` image run: | - docker build --target community -t "ocelotsocialnetwork/neo4j:latest" -t "ocelotsocialnetwork/neo4j:community" -t "ocelotsocialnetwork/neo4j:${VERSION}" -t "ocelotsocialnetwork/neo4j:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_ DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT neo4j/ + docker build --target community -t "ocelotsocialnetwork/neo4j:latest" -t "ocelotsocialnetwork/neo4j:community" -t "ocelotsocialnetwork/neo4j:${VERSION}" -t "ocelotsocialnetwork/neo4j:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT neo4j/ docker save "ocelotsocialnetwork/neo4j" > /tmp/neo4j.tar - name: Upload Artifact uses: actions/upload-artifact@v2 @@ -93,7 +93,7 @@ jobs: ########################################################################## - name: backend | Build `production` image run: | - docker build --target production -t "ocelotsocialnetwork/backend:latest" -t "ocelotsocialnetwork/backend:${VERSION}" -t "ocelotsocialnetwork/backend:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_ DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT backend/ + docker build --target production -t "ocelotsocialnetwork/backend:latest" -t "ocelotsocialnetwork/backend:${VERSION}" -t "ocelotsocialnetwork/backend:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT backend/ docker save "ocelotsocialnetwork/backend" > /tmp/backend.tar - name: Upload Artifact uses: actions/upload-artifact@v2 @@ -130,7 +130,7 @@ jobs: ########################################################################## - name: webapp | Build `production` image run: | - docker build --target production -t "ocelotsocialnetwork/webapp:latest" -t "ocelotsocialnetwork/webapp:${VERSION}" -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_ DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT webapp/ + docker build --target production -t "ocelotsocialnetwork/webapp:latest" -t "ocelotsocialnetwork/webapp:${VERSION}" -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT webapp/ docker save "ocelotsocialnetwork/webapp" > /tmp/webapp.tar - name: Upload Artifact uses: actions/upload-artifact@v2 @@ -168,7 +168,7 @@ jobs: - name: maintenance | Build `production` image # TODO: --target production run: | - docker build -t "ocelotsocialnetwork/maintenance:latest" -t "ocelotsocialnetwork/maintenance:${VERSION}" -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_ DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT webapp/ -f webapp/Dockerfile.maintenance + docker build -t "ocelotsocialnetwork/maintenance:latest" -t "ocelotsocialnetwork/maintenance:${VERSION}" -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT webapp/ -f webapp/Dockerfile.maintenance docker save "ocelotsocialnetwork/maintenance" > /tmp/maintenance.tar - name: Upload Artifact uses: actions/upload-artifact@v2 From 79beb840c5bbcd989603b219b45e218a96fd7b4d Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 13:15:45 +0200 Subject: [PATCH 04/15] -separate commands in two, docker build & save to allow multi-line commands -have arg and env variables --- .github/workflows/publish.yml | 66 +++++++++++++++++++++++++++-------- backend/Dockerfile | 10 ++++-- neo4j/Dockerfile | 11 +++--- webapp/Dockerfile | 11 +++--- 4 files changed, 72 insertions(+), 26 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 666266e39..a38c05561 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -55,9 +55,19 @@ jobs: # NEO4J ################################################################## ########################################################################## - name: Neo4J | Build `community` image - run: | - docker build --target community -t "ocelotsocialnetwork/neo4j:latest" -t "ocelotsocialnetwork/neo4j:community" -t "ocelotsocialnetwork/neo4j:${VERSION}" -t "ocelotsocialnetwork/neo4j:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT neo4j/ - docker save "ocelotsocialnetwork/neo4j" > /tmp/neo4j.tar + run: > + docker build + --target community + -t "ocelotsocialnetwork/neo4j:latest" + -t "ocelotsocialnetwork/neo4j:community" + -t "ocelotsocialnetwork/neo4j:${VERSION}" + -t "ocelotsocialnetwork/neo4j:${BUILD_VERSION}" + --build-arg BBUILD_DATE=$BUILD_DATE + --build-arg BBUILD_VERSION=$BUILD_VERSION + --build-arg BBUILD_COMMIT=$BUILD_COMMIT + neo4j/ + - name: Neo4J | Save docker image + run: docker save "ocelotsocialnetwork/neo4j" > /tmp/neo4j.tar - name: Upload Artifact uses: actions/upload-artifact@v2 with: @@ -91,10 +101,19 @@ jobs: ########################################################################## # BUILD BACKEND DOCKER IMAGE (production) ################################ ########################################################################## - - name: backend | Build `production` image - run: | - docker build --target production -t "ocelotsocialnetwork/backend:latest" -t "ocelotsocialnetwork/backend:${VERSION}" -t "ocelotsocialnetwork/backend:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT backend/ - docker save "ocelotsocialnetwork/backend" > /tmp/backend.tar + - name: Backend | Build `production` image + run: > + docker build + --target production + -t "ocelotsocialnetwork/backend:latest" + -t "ocelotsocialnetwork/backend:${VERSION}" + -t "ocelotsocialnetwork/backend:${BUILD_VERSION}" + --build-arg BBUILD_DATE=$BUILD_DATE + --build-arg BBUILD_VERSION=$BUILD_VERSION + --build-arg BBUILD_COMMIT=$BUILD_COMMIT + backend/ + - name: Backend | Save docker image + run: docker save "ocelotsocialnetwork/backend" > /tmp/backend.tar - name: Upload Artifact uses: actions/upload-artifact@v2 with: @@ -128,10 +147,19 @@ jobs: ########################################################################## # BUILD WEBAPP DOCKER IMAGE (build) ###################################### ########################################################################## - - name: webapp | Build `production` image - run: | - docker build --target production -t "ocelotsocialnetwork/webapp:latest" -t "ocelotsocialnetwork/webapp:${VERSION}" -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT webapp/ - docker save "ocelotsocialnetwork/webapp" > /tmp/webapp.tar + - name: Webapp | Build `production` image + run: > + docker build + --target production + -t "ocelotsocialnetwork/webapp:latest" + -t "ocelotsocialnetwork/webapp:${VERSION}" + -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}" + --build-arg BBUILD_DATE=$BUILD_DATE + --build-arg BBUILD_VERSION=$BUILD_VERSION + --build-arg BBUILD_COMMIT=$BUILD_COMMIT + webapp/ + - name: Webapp | Save docker image + run: docker save "ocelotsocialnetwork/webapp" > /tmp/webapp.tar - name: Upload Artifact uses: actions/upload-artifact@v2 with: @@ -165,11 +193,19 @@ jobs: ########################################################################## # BUILD MAINTENANCE DOCKER IMAGE (build) ################################# ########################################################################## - - name: maintenance | Build `production` image + - name: Maintenance | Build `production` image # TODO: --target production - run: | - docker build -t "ocelotsocialnetwork/maintenance:latest" -t "ocelotsocialnetwork/maintenance:${VERSION}" -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" --build-arg BUILD_DATE=$BUILD_DATE --build-arg BUILD_VERSION=$BUILD_VERSION --build-arg BUILD_COMMIT=$BUILD_COMMIT webapp/ -f webapp/Dockerfile.maintenance - docker save "ocelotsocialnetwork/maintenance" > /tmp/maintenance.tar + run: > + docker build + -t "ocelotsocialnetwork/maintenance:latest" + -t "ocelotsocialnetwork/maintenance:${VERSION}" + -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" + --build-arg BBUILD_DATE=$BUILD_DATE + --build-arg BBUILD_VERSION=$BUILD_VERSION + --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ + -f webapp/Dockerfile.maintenance + - name: Maintenance | Save docker image + run: docker save "ocelotsocialnetwork/maintenance" > /tmp/maintenance.tar - name: Upload Artifact uses: actions/upload-artifact@v2 with: diff --git a/backend/Dockerfile b/backend/Dockerfile index 146e1151a..c632f8803 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -3,14 +3,18 @@ ################################################################################## FROM node:12.19.0-alpine3.10 as base +# ENVs ## 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 -ARG BUILD_DATE="1970-01-01T00:00:00.00Z" +ARG BBUILD_DATE="1970-01-01T00:00:00.00Z" +ENV BUILD_DATE=$BBUILD_DATE ## We cannot do $(yarn run version)-${BUILD_NUMBER} here so we default to 0.0.0-0 -ARG BUILD_VERSION="0.0.0-0" +ARG BBUILD_VERSION="0.0.0-0" +ENV BUILD_VERSION=$BBUILD_VERSION ## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000 -ARG BUILD_COMMIT="0000000" +ARG BBUILD_COMMIT="0000000" +ENV BUILD_COMMIT=$BBUILD_COMMIT ## SET NODE_ENV ENV NODE_ENV="production" ## App relevant Envs diff --git a/neo4j/Dockerfile b/neo4j/Dockerfile index 79c4fb303..4bdc4ef1f 100644 --- a/neo4j/Dockerfile +++ b/neo4j/Dockerfile @@ -3,13 +3,16 @@ ################################################################################## FROM neo4j:3.5.14 as community -# ENVs (available in production aswell, can be overwritten by commandline or env file) +# ENVs ## We Cannot do `$(date -u +'%Y-%m-%dT%H:%M:%SZ')` here so we use unix timestamp=0 -ARG BUILD_DATE="1970-01-01T00:00:00.00Z" +ARG BBUILD_DATE="1970-01-01T00:00:00.00Z" +ENV BUILD_DATE=$BBUILD_DATE ## We cannot do $(yarn run version)-${BUILD_NUMBER} here so we default to 0.0.0-0 -ARG BUILD_VERSION="0.0.0-0" +ARG BBUILD_VERSION="0.0.0-0" +ENV BUILD_VERSION=$BBUILD_VERSION ## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000 -ARG BUILD_COMMIT="0000000" +ARG BBUILD_COMMIT="0000000" +ENV BUILD_COMMIT=$BBUILD_COMMIT # Labels LABEL org.label-schema.build-date="${BUILD_DATE}" diff --git a/webapp/Dockerfile b/webapp/Dockerfile index f4e96e202..75d43bf59 100644 --- a/webapp/Dockerfile +++ b/webapp/Dockerfile @@ -3,15 +3,18 @@ ################################################################################## FROM node:12.19.0-alpine3.10 as base -# ENVs (available in production aswell, can be overwritten by commandline or env file) +# ENVs ## 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 -ARG BUILD_DATE="1970-01-01T00:00:00.00Z" +ARG BBUILD_DATE="1970-01-01T00:00:00.00Z" +ENV BUILD_DATE=$BBUILD_DATE ## We cannot do $(yarn run version)-${BUILD_NUMBER} here so we default to 0.0.0-0 -ARG BUILD_VERSION="0.0.0-0" +ARG BBUILD_VERSION="0.0.0-0" +ENV BUILD_VERSION=$BBUILD_VERSION ## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000 -ARG BUILD_COMMIT="0000000" +ARG BBUILD_COMMIT="0000000" +ENV BUILD_COMMIT=$BBUILD_COMMIT ## SET NODE_ENV ENV NODE_ENV="production" ## App relevant Envs From 5dc844b431d3911d7ddbf3d22df170d56d1e2c7e Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 13:21:24 +0200 Subject: [PATCH 05/15] multi line simply doesnt work --- .github/workflows/publish.yml | 44 ++++------------------------------- 1 file changed, 4 insertions(+), 40 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a38c05561..426517e8e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -55,17 +55,7 @@ jobs: # NEO4J ################################################################## ########################################################################## - name: Neo4J | Build `community` image - run: > - docker build - --target community - -t "ocelotsocialnetwork/neo4j:latest" - -t "ocelotsocialnetwork/neo4j:community" - -t "ocelotsocialnetwork/neo4j:${VERSION}" - -t "ocelotsocialnetwork/neo4j:${BUILD_VERSION}" - --build-arg BBUILD_DATE=$BUILD_DATE - --build-arg BBUILD_VERSION=$BUILD_VERSION - --build-arg BBUILD_COMMIT=$BUILD_COMMIT - neo4j/ + run: docker build --target community -t "ocelotsocialnetwork/neo4j:latest" -t "ocelotsocialnetwork/neo4j:community" -t "ocelotsocialnetwork/neo4j:${VERSION}" -t "ocelotsocialnetwork/neo4j:${BUILD_VERSION}" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT neo4j/ - name: Neo4J | Save docker image run: docker save "ocelotsocialnetwork/neo4j" > /tmp/neo4j.tar - name: Upload Artifact @@ -102,16 +92,7 @@ jobs: # BUILD BACKEND DOCKER IMAGE (production) ################################ ########################################################################## - name: Backend | Build `production` image - run: > - docker build - --target production - -t "ocelotsocialnetwork/backend:latest" - -t "ocelotsocialnetwork/backend:${VERSION}" - -t "ocelotsocialnetwork/backend:${BUILD_VERSION}" - --build-arg BBUILD_DATE=$BUILD_DATE - --build-arg BBUILD_VERSION=$BUILD_VERSION - --build-arg BBUILD_COMMIT=$BUILD_COMMIT - backend/ + run: docker build --target production -t "ocelotsocialnetwork/backend:latest" -t "ocelotsocialnetwork/backend:${VERSION}" -t "ocelotsocialnetwork/backend:${BUILD_VERSION}" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT backend/ - name: Backend | Save docker image run: docker save "ocelotsocialnetwork/backend" > /tmp/backend.tar - name: Upload Artifact @@ -148,16 +129,7 @@ jobs: # BUILD WEBAPP DOCKER IMAGE (build) ###################################### ########################################################################## - name: Webapp | Build `production` image - run: > - docker build - --target production - -t "ocelotsocialnetwork/webapp:latest" - -t "ocelotsocialnetwork/webapp:${VERSION}" - -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}" - --build-arg BBUILD_DATE=$BUILD_DATE - --build-arg BBUILD_VERSION=$BUILD_VERSION - --build-arg BBUILD_COMMIT=$BUILD_COMMIT - webapp/ + run: docker build --target production -t "ocelotsocialnetwork/webapp:latest" -t "ocelotsocialnetwork/webapp:${VERSION}" -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ - name: Webapp | Save docker image run: docker save "ocelotsocialnetwork/webapp" > /tmp/webapp.tar - name: Upload Artifact @@ -195,15 +167,7 @@ jobs: ########################################################################## - name: Maintenance | Build `production` image # TODO: --target production - run: > - docker build - -t "ocelotsocialnetwork/maintenance:latest" - -t "ocelotsocialnetwork/maintenance:${VERSION}" - -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" - --build-arg BBUILD_DATE=$BUILD_DATE - --build-arg BBUILD_VERSION=$BUILD_VERSION - --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ - -f webapp/Dockerfile.maintenance + run: docker build -t "ocelotsocialnetwork/maintenance:latest" -t "ocelotsocialnetwork/maintenance:${VERSION}" -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ -f webapp/Dockerfile.maintenance - name: Maintenance | Save docker image run: docker save "ocelotsocialnetwork/maintenance" > /tmp/maintenance.tar - name: Upload Artifact From cb464832d6a90546950f1de95ea15f11c248a737 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 13:35:24 +0200 Subject: [PATCH 06/15] did some improvements on the maintenance docker image --- webapp/Dockerfile.maintenance | 59 ++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/webapp/Dockerfile.maintenance b/webapp/Dockerfile.maintenance index b02fe352b..19d316ced 100644 --- a/webapp/Dockerfile.maintenance +++ b/webapp/Dockerfile.maintenance @@ -1,19 +1,56 @@ +################################################################################## +# BASE ########################################################################### +################################################################################## FROM node:12.19.0-alpine3.10 as build -LABEL Description="Maintenance page of the Social Network ocelot.social" Vendor="ocelot.social Community" Version="0.0.1" Maintainer="ocelot.social Community (devops@ocelot.social)" -EXPOSE 3000 -CMD ["yarn", "run", "start"] +# ENVs +## 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 +ARG BBUILD_DATE="1970-01-01T00:00:00.00Z" +ENV BUILD_DATE=$BBUILD_DATE +## We cannot do $(yarn run version)-${BUILD_NUMBER} here so we default to 0.0.0-0 +ARG BBUILD_VERSION="0.0.0-0" +ENV BUILD_VERSION=$BBUILD_VERSION +## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000 +ARG BBUILD_COMMIT="0000000" +ENV BUILD_COMMIT=$BBUILD_COMMIT +## SET NODE_ENV +ENV NODE_ENV="production" +## App relevant Envs +ENV PORT="3000" -# Expose the app port -ARG BUILD_COMMIT -ENV BUILD_COMMIT=$BUILD_COMMIT -ARG WORKDIR=/develop-webapp -RUN mkdir -p $WORKDIR -WORKDIR $WORKDIR +# Labels +LABEL org.label-schema.build-date="${BUILD_DATE}" +LABEL org.label-schema.name="ocelot.social:backend" +LABEL org.label-schema.description="Maintenance page of the Social Network Software ocelot.social" +LABEL org.label-schema.usage="https://github.com/Ocelot-Social-Community/Ocelot-Social/blob/master/README.md" +LABEL org.label-schema.url="https://ocelot.social" +LABEL org.label-schema.vcs-url="https://github.com/Ocelot-Social-Community/Ocelot-Social/tree/master/backend" +LABEL org.label-schema.vcs-ref="${BUILD_COMMIT}" +LABEL org.label-schema.vendor="ocelot.social Community" +LABEL org.label-schema.version="${BUILD_VERSION}" +LABEL org.label-schema.schema-version="1.0" +LABEL maintainer="devops@ocelot.social" -# See: https://github.com/nodejs/docker-node/pull/367#issuecomment-430807898 +# Install Additional Software +## install: git RUN apk --no-cache add git +# Settings +## Expose Container Port +EXPOSE ${PORT} + +## Workdir +RUN mkdir -p ${DOCKER_WORKDIR} +WORKDIR ${DOCKER_WORKDIR} + +################################################################################## +# PRODUCTION ### TODO # TODO # TODO # TODO # TODO # TODO # TODO # TODO # TODO #### +################################################################################## + +CMD ["yarn", "run", "start"] + COPY package.json yarn.lock ./ RUN yarn install --production=false --frozen-lockfile --non-interactive @@ -37,6 +74,6 @@ RUN yarn run generate FROM nginx:alpine -COPY --from=build ./develop-webapp/dist/ /usr/share/nginx/html/ +COPY --from=build ./app/dedist/ /usr/share/nginx/html/ RUN rm /etc/nginx/conf.d/default.conf COPY maintenance/nginx/custom.conf /etc/nginx/conf.d/ From 1bf3f295c7a2fbb59d5fffe2e41b231dba5ecbbc Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 13:38:51 +0200 Subject: [PATCH 07/15] added production target removed todo --- .github/workflows/publish.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 426517e8e..3612fd3e0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -166,8 +166,7 @@ jobs: # BUILD MAINTENANCE DOCKER IMAGE (build) ################################# ########################################################################## - name: Maintenance | Build `production` image - # TODO: --target production - run: docker build -t "ocelotsocialnetwork/maintenance:latest" -t "ocelotsocialnetwork/maintenance:${VERSION}" -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ -f webapp/Dockerfile.maintenance + run: docker build --target production -t "ocelotsocialnetwork/maintenance:latest" -t "ocelotsocialnetwork/maintenance:${VERSION}" -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ -f webapp/Dockerfile.maintenance - name: Maintenance | Save docker image run: docker save "ocelotsocialnetwork/maintenance" > /tmp/maintenance.tar - name: Upload Artifact From 99364856bcfa644019806b7d1f26bbbf82f9139e Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 13:40:12 +0200 Subject: [PATCH 08/15] remove more todos --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9b8025ea3..9c67126e2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -253,7 +253,6 @@ jobs: ########################################################################## # COVERAGE REPORT FRONTEND ################################################ ########################################################################## - # TODO: Maybe remove this later on to avoid spam? #- name: frontend | Coverage report # uses: romeovs/lcov-reporter-action@v0.2.21 # with: From 6f1f5f360d54461bab42bced9aa792eafb9e10ab Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 13:45:32 +0200 Subject: [PATCH 09/15] actually define production stage in maintenance file --- webapp/Dockerfile.maintenance | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/Dockerfile.maintenance b/webapp/Dockerfile.maintenance index 19d316ced..4b8585754 100644 --- a/webapp/Dockerfile.maintenance +++ b/webapp/Dockerfile.maintenance @@ -48,6 +48,7 @@ WORKDIR ${DOCKER_WORKDIR} ################################################################################## # PRODUCTION ### TODO # TODO # TODO # TODO # TODO # TODO # TODO # TODO # TODO #### ################################################################################## +FROM base as production CMD ["yarn", "run", "start"] From b51fe45b076b22181954c529517d408e37332569 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 14:08:46 +0200 Subject: [PATCH 10/15] more fixes for the mainteace docker file --- webapp/Dockerfile.maintenance | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/webapp/Dockerfile.maintenance b/webapp/Dockerfile.maintenance index 4b8585754..ece01cdb4 100644 --- a/webapp/Dockerfile.maintenance +++ b/webapp/Dockerfile.maintenance @@ -45,13 +45,13 @@ EXPOSE ${PORT} RUN mkdir -p ${DOCKER_WORKDIR} WORKDIR ${DOCKER_WORKDIR} -################################################################################## -# PRODUCTION ### TODO # TODO # TODO # TODO # TODO # TODO # TODO # TODO # TODO #### -################################################################################## -FROM base as production - CMD ["yarn", "run", "start"] +################################################################################## +# BUILD ### TODO # TODO # TODO # TODO # TODO # TODO # TODO # TODO # TODO # TODO ## +################################################################################## +FROM base as build + COPY package.json yarn.lock ./ RUN yarn install --production=false --frozen-lockfile --non-interactive @@ -73,8 +73,11 @@ COPY maintenance/source ./ RUN yarn run generate +################################################################################## +# PRODUCTION ### TODO # TODO # TODO # TODO # TODO # TODO # TODO # TODO # TODO #### +################################################################################## +FROM nginx:alpine as production -FROM nginx:alpine COPY --from=build ./app/dedist/ /usr/share/nginx/html/ RUN rm /etc/nginx/conf.d/default.conf COPY maintenance/nginx/custom.conf /etc/nginx/conf.d/ From 94a6bdb137d22421cbf31b438b7ce49c8b534404 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 14:13:20 +0200 Subject: [PATCH 11/15] more maintenance fixes --- webapp/Dockerfile.maintenance | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/Dockerfile.maintenance b/webapp/Dockerfile.maintenance index ece01cdb4..66c8516dd 100644 --- a/webapp/Dockerfile.maintenance +++ b/webapp/Dockerfile.maintenance @@ -1,7 +1,7 @@ ################################################################################## # BASE ########################################################################### ################################################################################## -FROM node:12.19.0-alpine3.10 as build +FROM node:12.19.0-alpine3.10 as base # ENVs ## DOCKER_WORKDIR would be a classical ARG, but that is not multi layer persistent - shame From 87a5daa7a33c4e7fe6893e51d1f9e5815611aff3 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 14:23:45 +0200 Subject: [PATCH 12/15] old workig directory in the hope it fixes stuff --- webapp/Dockerfile.maintenance | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/Dockerfile.maintenance b/webapp/Dockerfile.maintenance index 66c8516dd..ee1cb8293 100644 --- a/webapp/Dockerfile.maintenance +++ b/webapp/Dockerfile.maintenance @@ -5,7 +5,7 @@ FROM node:12.19.0-alpine3.10 as base # ENVs ## DOCKER_WORKDIR would be a classical ARG, but that is not multi layer persistent - shame -ENV DOCKER_WORKDIR="/app" +ENV DOCKER_WORKDIR="/develop-webapp" ## We Cannot do `$(date -u +'%Y-%m-%dT%H:%M:%SZ')` here so we use unix timestamp=0 ARG BBUILD_DATE="1970-01-01T00:00:00.00Z" ENV BUILD_DATE=$BBUILD_DATE @@ -78,6 +78,6 @@ RUN yarn run generate ################################################################################## FROM nginx:alpine as production -COPY --from=build ./app/dedist/ /usr/share/nginx/html/ +COPY --from=build ./develop-webapp/dedist/ /usr/share/nginx/html/ RUN rm /etc/nginx/conf.d/default.conf COPY maintenance/nginx/custom.conf /etc/nginx/conf.d/ From a2e93bb17b4617b0d18a5c4d9820b052f23f1eed Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 14:45:07 +0200 Subject: [PATCH 13/15] fix maintenance --- webapp/Dockerfile.maintenance | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/Dockerfile.maintenance b/webapp/Dockerfile.maintenance index ee1cb8293..51b30e405 100644 --- a/webapp/Dockerfile.maintenance +++ b/webapp/Dockerfile.maintenance @@ -5,7 +5,7 @@ FROM node:12.19.0-alpine3.10 as base # ENVs ## DOCKER_WORKDIR would be a classical ARG, but that is not multi layer persistent - shame -ENV DOCKER_WORKDIR="/develop-webapp" +ENV DOCKER_WORKDIR="/app" ## We Cannot do `$(date -u +'%Y-%m-%dT%H:%M:%SZ')` here so we use unix timestamp=0 ARG BBUILD_DATE="1970-01-01T00:00:00.00Z" ENV BUILD_DATE=$BBUILD_DATE @@ -78,6 +78,6 @@ RUN yarn run generate ################################################################################## FROM nginx:alpine as production -COPY --from=build ./develop-webapp/dedist/ /usr/share/nginx/html/ +COPY --from=base ./app/dedist/ /usr/share/nginx/html/ RUN rm /etc/nginx/conf.d/default.conf COPY maintenance/nginx/custom.conf /etc/nginx/conf.d/ From 0f18fb2b47ab79809509853d527bac074675d4f0 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 14:54:16 +0200 Subject: [PATCH 14/15] more fixes --- webapp/Dockerfile.maintenance | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/Dockerfile.maintenance b/webapp/Dockerfile.maintenance index 51b30e405..0a7616240 100644 --- a/webapp/Dockerfile.maintenance +++ b/webapp/Dockerfile.maintenance @@ -78,6 +78,6 @@ RUN yarn run generate ################################################################################## FROM nginx:alpine as production -COPY --from=base ./app/dedist/ /usr/share/nginx/html/ +COPY --from=build ./app/dist/ /usr/share/nginx/html/ RUN rm /etc/nginx/conf.d/default.conf COPY maintenance/nginx/custom.conf /etc/nginx/conf.d/ From 3a645dd0780880757c7168cab45f3e4fe5f45051 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Sat, 17 Apr 2021 15:21:50 +0200 Subject: [PATCH 15/15] publish only on master --- .github/workflows/publish.yml | 262 +++++++++++++++++----------------- 1 file changed, 131 insertions(+), 131 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3612fd3e0..de956e17b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,8 +2,8 @@ name: ocelot.social publish CI on: push: -# branches: -# - master + branches: + - master jobs: ############################################################################## @@ -175,132 +175,132 @@ jobs: name: docker-maintenance-production path: /tmp/maintenance.tar -# ############################################################################## -# # JOB: UPLOAD TO DOCKERHUB ################################################### -# ############################################################################## -# upload_to_dockerhub: -# name: Upload to Dockerhub -# runs-on: ubuntu-latest -# needs: [build_production_neo4j,build_production_backend,build_production_webapp,build_production_maintenance] -# env: -# DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} -# DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} -# steps: -# ########################################################################## -# # CHECKOUT CODE ########################################################## -# ########################################################################## -# - name: Checkout code -# uses: actions/checkout@v2 -# ########################################################################## -# # DOWNLOAD DOCKER IMAGES ################################################# -# ########################################################################## -# - name: Download Docker Image (Neo4J) -# uses: actions/download-artifact@v2 -# with: -# name: docker-neo4j-community -# path: /tmp -# - name: Load Docker Image -# run: docker load < /tmp/neo4j.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 (WebApp) -# uses: actions/download-artifact@v2 -# with: -# name: docker-webapp-production -# path: /tmp -# - name: Load Docker Image -# run: docker load < /tmp/webapp.tar -# - name: Download Docker Image (Maintenance) -# uses: actions/download-artifact@v2 -# with: -# name: docker-maintenance-production -# path: /tmp -# - name: Load Docker Image -# run: docker load < /tmp/maintenance.tar -# ########################################################################## -# # Upload ################################################################# -# ########################################################################## -# - name: login to dockerhub -# run: echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin -# - name: Push neo4j -# run: docker push --all-tags ocelotsocialnetwork/neo4j -# - name: Push backend -# run: docker push --all-tags ocelotsocialnetwork/backend -# - name: Push webapp -# run: docker push --all-tags ocelotsocialnetwork/webapp -# - name: Push maintenance -# run: docker push --all-tags ocelotsocialnetwork/maintenance -# -# ############################################################################## -# # JOB: GITHUB TAG LATEST VERSION ############################################# -# ############################################################################## -# github_tag: -# name: Tag latest version on Github -# runs-on: ubuntu-latest -# needs: [upload_to_dockerhub] -# steps: -# ########################################################################## -# # CHECKOUT CODE ########################################################## -# ########################################################################## -# - name: Checkout code -# uses: actions/checkout@v2 -# with: -# fetch-depth: 0 # Fetch full History for changelog -# ########################################################################## -# # 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 -# ########################################################################## -# # Push version tag to GitHub ############################################# -# ########################################################################## -# # TODO: this will error on duplicate -# #- name: package-version-to-git-tag -# # uses: pkgdeps/git-tag-action@v2 -# # with: -# # github_token: ${{ secrets.GITHUB_TOKEN }} -# # github_repo: ${{ github.repository }} -# # version: ${{ env.VERSION }} -# # git_commit_sha: ${{ github.sha }} -# # git_tag_prefix: "v" -# ########################################################################## -# # Push build tag to GitHub ############################################### -# ########################################################################## -# - name: package-version-to-git-tag + build number -# uses: pkgdeps/git-tag-action@v2 -# with: -# github_token: ${{ secrets.GITHUB_TOKEN }} -# github_repo: ${{ github.repository }} -# version: ${{ env.BUILD_VERSION }} -# git_commit_sha: ${{ github.sha }} -# git_tag_prefix: "b" -# ########################################################################## -# # Push release tag to GitHub ############################################# -# ########################################################################## -# - name: yarn install -# run: yarn install -# - name: generate changelog -# run: yarn auto-changelog --latest-version ${{ env.VERSION }} --unreleased-only -# - name: package-version-to-git-release -# continue-on-error: true # Will fail if tag exists -# id: create_release -# uses: actions/create-release@v1 -# env: -# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token -# with: -# tag_name: ${{ env.VERSION }} -# release_name: ${{ env.VERSION }} -# body_path: ./CHANGELOG.md -# draft: false -# prerelease: false \ No newline at end of file + ############################################################################## + # JOB: UPLOAD TO DOCKERHUB ################################################### + ############################################################################## + upload_to_dockerhub: + name: Upload to Dockerhub + runs-on: ubuntu-latest + needs: [build_production_neo4j,build_production_backend,build_production_webapp,build_production_maintenance] + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + steps: + ########################################################################## + # CHECKOUT CODE ########################################################## + ########################################################################## + - name: Checkout code + uses: actions/checkout@v2 + ########################################################################## + # DOWNLOAD DOCKER IMAGES ################################################# + ########################################################################## + - name: Download Docker Image (Neo4J) + uses: actions/download-artifact@v2 + with: + name: docker-neo4j-community + path: /tmp + - name: Load Docker Image + run: docker load < /tmp/neo4j.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 (WebApp) + uses: actions/download-artifact@v2 + with: + name: docker-webapp-production + path: /tmp + - name: Load Docker Image + run: docker load < /tmp/webapp.tar + - name: Download Docker Image (Maintenance) + uses: actions/download-artifact@v2 + with: + name: docker-maintenance-production + path: /tmp + - name: Load Docker Image + run: docker load < /tmp/maintenance.tar + ########################################################################## + # Upload ################################################################# + ########################################################################## + - name: login to dockerhub + run: echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin + - name: Push neo4j + run: docker push --all-tags ocelotsocialnetwork/neo4j + - name: Push backend + run: docker push --all-tags ocelotsocialnetwork/backend + - name: Push webapp + run: docker push --all-tags ocelotsocialnetwork/webapp + - name: Push maintenance + run: docker push --all-tags ocelotsocialnetwork/maintenance + + ############################################################################## + # JOB: GITHUB TAG LATEST VERSION ############################################# + ############################################################################## + github_tag: + name: Tag latest version on Github + runs-on: ubuntu-latest + needs: [upload_to_dockerhub] + steps: + ########################################################################## + # CHECKOUT CODE ########################################################## + ########################################################################## + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 # Fetch full History for changelog + ########################################################################## + # 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 + ########################################################################## + # Push version tag to GitHub ############################################# + ########################################################################## + # TODO: this will error on duplicate + #- name: package-version-to-git-tag + # uses: pkgdeps/git-tag-action@v2 + # with: + # github_token: ${{ secrets.GITHUB_TOKEN }} + # github_repo: ${{ github.repository }} + # version: ${{ env.VERSION }} + # git_commit_sha: ${{ github.sha }} + # git_tag_prefix: "v" + ########################################################################## + # Push build tag to GitHub ############################################### + ########################################################################## + - name: package-version-to-git-tag + build number + uses: pkgdeps/git-tag-action@v2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + github_repo: ${{ github.repository }} + version: ${{ env.BUILD_VERSION }} + git_commit_sha: ${{ github.sha }} + git_tag_prefix: "b" + ########################################################################## + # Push release tag to GitHub ############################################# + ########################################################################## + - name: yarn install + run: yarn install + - name: generate changelog + run: yarn auto-changelog --latest-version ${{ env.VERSION }} --unreleased-only + - name: package-version-to-git-release + continue-on-error: true # Will fail if tag exists + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: ${{ env.VERSION }} + release_name: ${{ env.VERSION }} + body_path: ./CHANGELOG.md + draft: false + prerelease: false \ No newline at end of file