Use build args instead of envs for the version, date & commit

This commit is contained in:
Ulf Gebhardt 2021-04-17 12:44:01 +02:00
parent 6773633282
commit d354f9630a
No known key found for this signature in database
GPG Key ID: 81308EFE29ABFEBD
4 changed files with 176 additions and 145 deletions

View File

@ -2,8 +2,8 @@ name: ocelot.social publish CI
on: on:
push: push:
branches: # branches:
- master # - master
jobs: jobs:
############################################################################## ##############################################################################
@ -56,7 +56,16 @@ jobs:
########################################################################## ##########################################################################
- name: Neo4J | Build `community` image - name: Neo4J | Build `community` image
run: | 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 docker save "ocelotsocialnetwork/neo4j" > /tmp/neo4j.tar
- name: Upload Artifact - name: Upload Artifact
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
@ -93,7 +102,15 @@ jobs:
########################################################################## ##########################################################################
- name: backend | Build `production` image - name: backend | Build `production` image
run: | 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 docker save "ocelotsocialnetwork/backend" > /tmp/backend.tar
- name: Upload Artifact - name: Upload Artifact
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
@ -130,7 +147,15 @@ jobs:
########################################################################## ##########################################################################
- name: webapp | Build `production` image - name: webapp | Build `production` image
run: | 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 docker save "ocelotsocialnetwork/webapp" > /tmp/webapp.tar
- name: Upload Artifact - name: Upload Artifact
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
@ -168,7 +193,14 @@ jobs:
- name: maintenance | Build `production` image - name: maintenance | Build `production` image
# TODO: --target production # TODO: --target production
run: | 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 docker save "ocelotsocialnetwork/maintenance" > /tmp/maintenance.tar
- name: Upload Artifact - name: Upload Artifact
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
@ -176,132 +208,132 @@ jobs:
name: docker-maintenance-production name: docker-maintenance-production
path: /tmp/maintenance.tar path: /tmp/maintenance.tar
############################################################################## # ##############################################################################
# JOB: UPLOAD TO DOCKERHUB ################################################### # # JOB: UPLOAD TO DOCKERHUB ###################################################
############################################################################## # ##############################################################################
upload_to_dockerhub: # upload_to_dockerhub:
name: Upload to Dockerhub # name: Upload to Dockerhub
runs-on: ubuntu-latest # runs-on: ubuntu-latest
needs: [build_production_neo4j,build_production_backend,build_production_webapp,build_production_maintenance] # needs: [build_production_neo4j,build_production_backend,build_production_webapp,build_production_maintenance]
env: # env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} # DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} # DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
steps: # steps:
########################################################################## # ##########################################################################
# CHECKOUT CODE ########################################################## # # CHECKOUT CODE ##########################################################
########################################################################## # ##########################################################################
- name: Checkout code # - name: Checkout code
uses: actions/checkout@v2 # uses: actions/checkout@v2
########################################################################## # ##########################################################################
# DOWNLOAD DOCKER IMAGES ################################################# # # DOWNLOAD DOCKER IMAGES #################################################
########################################################################## # ##########################################################################
- name: Download Docker Image (Neo4J) # - name: Download Docker Image (Neo4J)
uses: actions/download-artifact@v2 # uses: actions/download-artifact@v2
with: # with:
name: docker-neo4j-community # name: docker-neo4j-community
path: /tmp # path: /tmp
- name: Load Docker Image # - name: Load Docker Image
run: docker load < /tmp/neo4j.tar # run: docker load < /tmp/neo4j.tar
- name: Download Docker Image (Backend) # - name: Download Docker Image (Backend)
uses: actions/download-artifact@v2 # uses: actions/download-artifact@v2
with: # with:
name: docker-backend-production # name: docker-backend-production
path: /tmp # path: /tmp
- name: Load Docker Image # - name: Load Docker Image
run: docker load < /tmp/backend.tar # run: docker load < /tmp/backend.tar
- name: Download Docker Image (WebApp) # - name: Download Docker Image (WebApp)
uses: actions/download-artifact@v2 # uses: actions/download-artifact@v2
with: # with:
name: docker-webapp-production # name: docker-webapp-production
path: /tmp # path: /tmp
- name: Load Docker Image # - name: Load Docker Image
run: docker load < /tmp/webapp.tar # run: docker load < /tmp/webapp.tar
- name: Download Docker Image (Maintenance) # - name: Download Docker Image (Maintenance)
uses: actions/download-artifact@v2 # uses: actions/download-artifact@v2
with: # with:
name: docker-maintenance-production # name: docker-maintenance-production
path: /tmp # path: /tmp
- name: Load Docker Image # - name: Load Docker Image
run: docker load < /tmp/maintenance.tar # run: docker load < /tmp/maintenance.tar
########################################################################## # ##########################################################################
# Upload ################################################################# # # Upload #################################################################
########################################################################## # ##########################################################################
- name: login to dockerhub # - name: login to dockerhub
run: echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin # run: echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin
- name: Push neo4j # - name: Push neo4j
run: docker push --all-tags ocelotsocialnetwork/neo4j # run: docker push --all-tags ocelotsocialnetwork/neo4j
- name: Push backend # - name: Push backend
run: docker push --all-tags ocelotsocialnetwork/backend # run: docker push --all-tags ocelotsocialnetwork/backend
- name: Push webapp # - name: Push webapp
run: docker push --all-tags ocelotsocialnetwork/webapp # run: docker push --all-tags ocelotsocialnetwork/webapp
- name: Push maintenance # - name: Push maintenance
run: docker push --all-tags ocelotsocialnetwork/maintenance # run: docker push --all-tags ocelotsocialnetwork/maintenance
#
############################################################################## # ##############################################################################
# JOB: GITHUB TAG LATEST VERSION ############################################# # # JOB: GITHUB TAG LATEST VERSION #############################################
############################################################################## # ##############################################################################
github_tag: # github_tag:
name: Tag latest version on Github # name: Tag latest version on Github
runs-on: ubuntu-latest # runs-on: ubuntu-latest
needs: [upload_to_dockerhub] # needs: [upload_to_dockerhub]
steps: # steps:
########################################################################## # ##########################################################################
# CHECKOUT CODE ########################################################## # # CHECKOUT CODE ##########################################################
########################################################################## # ##########################################################################
- name: Checkout code # - name: Checkout code
uses: actions/checkout@v2 # uses: actions/checkout@v2
with: # with:
fetch-depth: 0 # Fetch full History for changelog # fetch-depth: 0 # Fetch full History for changelog
########################################################################## # ##########################################################################
# SET ENVS ############################################################### # # SET ENVS ###############################################################
########################################################################## # ##########################################################################
- name: ENV - VERSION # - name: ENV - VERSION
run: echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV # run: echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV
- name: ENV - BUILD_DATE # - name: ENV - BUILD_DATE
run: echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV # run: echo "BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV
- name: ENV - BUILD_VERSION # - name: ENV - BUILD_VERSION
run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV # run: echo "BUILD_VERSION=${VERSION}-${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV
- name: ENV - BUILD_COMMIT # - name: ENV - BUILD_COMMIT
run: echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV # run: echo "BUILD_COMMIT=${GITHUB_SHA}" >> $GITHUB_ENV
########################################################################## # ##########################################################################
# Push version tag to GitHub ############################################# # # Push version tag to GitHub #############################################
########################################################################## # ##########################################################################
# TODO: this will error on duplicate # # TODO: this will error on duplicate
#- name: package-version-to-git-tag # #- name: package-version-to-git-tag
# uses: pkgdeps/git-tag-action@v2 # # uses: pkgdeps/git-tag-action@v2
# with: # # with:
# github_token: ${{ secrets.GITHUB_TOKEN }} # # github_token: ${{ secrets.GITHUB_TOKEN }}
# github_repo: ${{ github.repository }} # # github_repo: ${{ github.repository }}
# version: ${{ env.VERSION }} # # version: ${{ env.VERSION }}
# git_commit_sha: ${{ github.sha }} # # git_commit_sha: ${{ github.sha }}
# git_tag_prefix: "v" # # git_tag_prefix: "v"
########################################################################## # ##########################################################################
# Push build tag to GitHub ############################################### # # Push build tag to GitHub ###############################################
########################################################################## # ##########################################################################
- name: package-version-to-git-tag + build number # - name: package-version-to-git-tag + build number
uses: pkgdeps/git-tag-action@v2 # uses: pkgdeps/git-tag-action@v2
with: # with:
github_token: ${{ secrets.GITHUB_TOKEN }} # github_token: ${{ secrets.GITHUB_TOKEN }}
github_repo: ${{ github.repository }} # github_repo: ${{ github.repository }}
version: ${{ env.BUILD_VERSION }} # version: ${{ env.BUILD_VERSION }}
git_commit_sha: ${{ github.sha }} # git_commit_sha: ${{ github.sha }}
git_tag_prefix: "b" # git_tag_prefix: "b"
########################################################################## # ##########################################################################
# Push release tag to GitHub ############################################# # # Push release tag to GitHub #############################################
########################################################################## # ##########################################################################
- name: yarn install # - name: yarn install
run: yarn install # run: yarn install
- name: generate changelog # - name: generate changelog
run: yarn auto-changelog --latest-version ${{ env.VERSION }} --unreleased-only # run: yarn auto-changelog --latest-version ${{ env.VERSION }} --unreleased-only
- name: package-version-to-git-release # - name: package-version-to-git-release
continue-on-error: true # Will fail if tag exists # continue-on-error: true # Will fail if tag exists
id: create_release # id: create_release
uses: actions/create-release@v1 # uses: actions/create-release@v1
env: # env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with: # with:
tag_name: ${{ env.VERSION }} # tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }} # release_name: ${{ env.VERSION }}
body_path: ./CHANGELOG.md # body_path: ./CHANGELOG.md
draft: false # draft: false
prerelease: false # prerelease: false

View File

@ -3,15 +3,14 @@
################################################################################## ##################################################################################
FROM node:12.19.0-alpine3.10 as base 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 ## DOCKER_WORKDIR would be a classical ARG, but that is not multi layer persistent - shame
ENV DOCKER_WORKDIR="/app" ENV DOCKER_WORKDIR="/app"
## We Cannot do `$(date -u +'%Y-%m-%dT%H:%M:%SZ')` here so we use unix timestamp=0 ## 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 ## 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 ## 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 ## SET NODE_ENV
ENV NODE_ENV="production" ENV NODE_ENV="production"
## App relevant Envs ## App relevant Envs

View File

@ -5,11 +5,11 @@ FROM neo4j:3.5.14 as community
# ENVs (available in production aswell, can be overwritten by commandline or env file) # 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 ## 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 ## 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 ## We cannot do `$(git rev-parse --short HEAD)` here so we default to 0000000
ENV BUILD_COMMIT="0000000" ARG BUILD_COMMIT="0000000"
# Labels # Labels
LABEL org.label-schema.build-date="${BUILD_DATE}" LABEL org.label-schema.build-date="${BUILD_DATE}"

View File

@ -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 ## DOCKER_WORKDIR would be a classical ARG, but that is not multi layer persistent - shame
ENV DOCKER_WORKDIR="/app" ENV DOCKER_WORKDIR="/app"
## We Cannot do `$(date -u +'%Y-%m-%dT%H:%M:%SZ')` here so we use unix timestamp=0 ## 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 ## 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 ## 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 ## SET NODE_ENV
ENV NODE_ENV="production" ENV NODE_ENV="production"
## App relevant Envs ## App relevant Envs