mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
394 lines
24 KiB
YAML
394 lines
24 KiB
YAML
name: ocelot.social publish CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
# - 5059-epic-groups # for testing while developing
|
|
# template branches in repo
|
|
# - template--separate-branch-auto-deployment--5059-epic-groups
|
|
|
|
jobs:
|
|
##############################################################################
|
|
# JOB: PREPARE ###############################################################
|
|
##############################################################################
|
|
prepare:
|
|
name: Prepare
|
|
runs-on: ubuntu-latest
|
|
# needs: [nothing]
|
|
steps:
|
|
##########################################################################
|
|
# CHECKOUT CODE ##########################################################
|
|
##########################################################################
|
|
- name: Checkout code
|
|
uses: actions/checkout@v2
|
|
##########################################################################
|
|
# TODO: DO STUFF ??? #####################################################
|
|
##########################################################################
|
|
- name: Check translation files
|
|
run: |
|
|
scripts/translations/sort.sh
|
|
scripts/translations/missing-keys.sh
|
|
|
|
##############################################################################
|
|
# JOB: DOCKER BUILD COMMUNITY NEO4J ##########################################
|
|
##############################################################################
|
|
build_production_neo4j:
|
|
name: Docker Build Production - Neo4J
|
|
runs-on: ubuntu-latest
|
|
needs: [prepare]
|
|
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
|
|
##########################################################################
|
|
# NEO4J ##################################################################
|
|
##########################################################################
|
|
- name: Neo4J | Build `community` image
|
|
run: docker build --target community -t "ocelotsocialnetwork/neo4j-community:latest" -t "ocelotsocialnetwork/neo4j-community:${VERSION}" -t "ocelotsocialnetwork/neo4j-community:${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-community" > /tmp/neo4j.tar
|
|
- name: Upload Artifact
|
|
uses: actions/upload-artifact@v2
|
|
with:
|
|
name: docker-neo4j-community
|
|
path: /tmp/neo4j.tar
|
|
|
|
##############################################################################
|
|
# JOB: DOCKER BUILD PRODUCTION BACKEND #######################################
|
|
##############################################################################
|
|
build_production_backend:
|
|
name: Docker Build Production - Backend
|
|
runs-on: ubuntu-latest
|
|
needs: [prepare]
|
|
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
|
|
##########################################################################
|
|
# BUILD BACKEND DOCKER IMAGE (production) ################################
|
|
##########################################################################
|
|
- name: Backend | Build `production` image
|
|
run: |
|
|
docker build --target base -t "ocelotsocialnetwork/backend:latest-base" -t "ocelotsocialnetwork/backend:${VERSION}-base" -t "ocelotsocialnetwork/backend:${BUILD_VERSION}-base" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT backend/
|
|
docker build --target code -t "ocelotsocialnetwork/backend:latest-code" -t "ocelotsocialnetwork/backend:${VERSION}-code" -t "ocelotsocialnetwork/backend:${BUILD_VERSION}-code" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT backend/
|
|
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:
|
|
name: docker-backend-production
|
|
path: /tmp/backend.tar
|
|
|
|
##############################################################################
|
|
# JOB: DOCKER BUILD PRODUCTION WEBAPP ########################################
|
|
##############################################################################
|
|
build_production_webapp:
|
|
name: Docker Build Production - WebApp
|
|
runs-on: ubuntu-latest
|
|
needs: [prepare]
|
|
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
|
|
##########################################################################
|
|
# BUILD WEBAPP DOCKER IMAGE (build) ######################################
|
|
##########################################################################
|
|
- name: Webapp | Build `production` image
|
|
run: |
|
|
docker build --target base -t "ocelotsocialnetwork/webapp:latest-base" -t "ocelotsocialnetwork/webapp:${VERSION}-base" -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}-base" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/
|
|
docker build --target code -t "ocelotsocialnetwork/webapp:latest-code" -t "ocelotsocialnetwork/webapp:${VERSION}-code" -t "ocelotsocialnetwork/webapp:${BUILD_VERSION}-code" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/
|
|
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:
|
|
name: docker-webapp-production
|
|
path: /tmp/webapp.tar
|
|
|
|
##############################################################################
|
|
# JOB: DOCKER BUILD PRODUCTION MAINTENANCE ###################################
|
|
##############################################################################
|
|
build_production_maintenance:
|
|
name: Docker Build Production - Maintenance
|
|
runs-on: ubuntu-latest
|
|
needs: [prepare]
|
|
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
|
|
##########################################################################
|
|
# BUILD MAINTENANCE DOCKER IMAGE (build) #################################
|
|
##########################################################################
|
|
- name: Maintenance | Build `production` image
|
|
run: |
|
|
docker build --target base -t "ocelotsocialnetwork/maintenance:latest-base" -t "ocelotsocialnetwork/maintenance:${VERSION}-base" -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}-base" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ -f webapp/Dockerfile.maintenance
|
|
docker build --target code -t "ocelotsocialnetwork/maintenance:latest-code" -t "ocelotsocialnetwork/maintenance:${VERSION}-code" -t "ocelotsocialnetwork/maintenance:${BUILD_VERSION}-code" --build-arg BBUILD_DATE=$BUILD_DATE --build-arg BBUILD_VERSION=$BUILD_VERSION --build-arg BBUILD_COMMIT=$BUILD_COMMIT webapp/ -f webapp/Dockerfile.maintenance
|
|
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
|
|
uses: actions/upload-artifact@v2
|
|
with:
|
|
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-community
|
|
- 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: KUBERNETES DEPLOY ACTUAL/LATEST VERSION ######################################
|
|
##############################################################################
|
|
kubernetes_deploy:
|
|
# see example https://github.com/do-community/example-doctl-action
|
|
# see example https://github.com/do-community/example-doctl-action/blob/main/.github/workflows/workflow.yaml
|
|
name: Kubernetes deploy of latest version to stage.ocelot.social cluster at DigitalOcean
|
|
runs-on: ubuntu-latest
|
|
needs: [upload_to_dockerhub]
|
|
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_VERSION
|
|
run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV
|
|
##########################################################################
|
|
# Install DigitalOceans doctl and set kubeconfig #########################
|
|
##########################################################################
|
|
- name: Install doctl
|
|
uses: digitalocean/action-doctl@v2
|
|
with:
|
|
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
|
|
- name: Save DigitalOcean kubeconfig with short-lived credentials
|
|
run: doctl kubernetes cluster kubeconfig save --expiry-seconds 600 cluster-stage-ocelot-social
|
|
##########################################################################
|
|
# Deploy new Docker images to DigitalOcean Kubernetes cluster ############
|
|
##########################################################################
|
|
# - name: Deploy 'latest' to DigitalOcean Kubernetes
|
|
# run: |
|
|
# kubectl -n default set image deployment/ocelot-webapp container-ocelot-webapp=ocelotsocialnetwork/webapp:latest
|
|
# kubectl -n default rollout restart deployment/ocelot-webapp
|
|
# kubectl -n default set image deployment/ocelot-backend container-ocelot-backend=ocelotsocialnetwork/backend:latest
|
|
# kubectl -n default rollout restart deployment/ocelot-backend
|
|
# kubectl -n default set image deployment/ocelot-maintenance container-ocelot-maintenance=ocelotsocialnetwork/maintenance:latest
|
|
# kubectl -n default rollout restart deployment/ocelot-maintenance
|
|
# kubectl -n default set image deployment/ocelot-neo4j container-ocelot-neo4j=ocelotsocialnetwork/neo4j-community:latest
|
|
# kubectl -n default rollout restart deployment/ocelot-neo4j
|
|
- name: Deploy actual version '$BUILD_VERSION' to DigitalOcean Kubernetes
|
|
run: |
|
|
kubectl -n default set image deployment/ocelot-webapp container-ocelot-webapp=ocelotsocialnetwork/webapp:$BUILD_VERSION
|
|
kubectl -n default rollout restart deployment/ocelot-webapp
|
|
kubectl -n default set image deployment/ocelot-backend container-ocelot-backend=ocelotsocialnetwork/backend:$BUILD_VERSION
|
|
kubectl -n default rollout restart deployment/ocelot-backend
|
|
kubectl -n default set image deployment/ocelot-maintenance container-ocelot-maintenance=ocelotsocialnetwork/maintenance:$BUILD_VERSION
|
|
kubectl -n default rollout restart deployment/ocelot-maintenance
|
|
kubectl -n default set image deployment/ocelot-neo4j container-ocelot-neo4j=ocelotsocialnetwork/neo4j-community:$BUILD_VERSION
|
|
kubectl -n default rollout restart deployment/ocelot-neo4j
|
|
# because this step 'kubectl -n default rollout status deployment/* --timeout=600s' does not work as expected
|
|
# and we need the pods to be up again for cleaning and seeding the Neo4j database and the backend.
|
|
# !!! this is not a perfect solution !!!
|
|
# deployments are regularly up again after 3 minutes and 10 seconds
|
|
- name: Sleep for 4 minutes, means 240 seconds
|
|
run: sleep 240s
|
|
shell: bash
|
|
- name: Verify deployment and wait for the pods of each deployment to get ready for cleaning and seeding of the database
|
|
run: |
|
|
kubectl -n default rollout status deployment/ocelot-backend --timeout=600s
|
|
kubectl -n default rollout status deployment/ocelot-neo4j --timeout=600s
|
|
kubectl -n default rollout status deployment/ocelot-maintenance --timeout=600s
|
|
kubectl -n default rollout status deployment/ocelot-webapp --timeout=600s
|
|
- name: Run migrations for Neo4j database via backend for staging
|
|
run: |
|
|
kubectl -n default exec -it $(kubectl -n default get pods | grep ocelot-backend | awk '{ print $1 }') -- /bin/sh -c "yarn prod:migrate up"
|
|
- name: Reset and seed Neo4j database via backend for staging
|
|
# db cleaning and seeding is only possible in production if env 'PRODUCTION_DB_CLEAN_ALLOW=true' is set in deployment
|
|
run: |
|
|
kubectl -n default exec -it $(kubectl -n default get pods | grep ocelot-backend | awk '{ print $1 }') -- /bin/sh -c "node --experimental-repl-await dist/db/clean.js && node --experimental-repl-await dist/db/seed.js"
|
|
|
|
##############################################################################
|
|
# 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
|