Skip to content

Nightly image build and push #793

Nightly image build and push

Nightly image build and push #793

Workflow file for this run

# Nightly build of a snapshot version
# and a docker image which is pushed
# to a docker registry
name: Nightly image build and push
on:
workflow_dispatch:
inputs:
forced:
description: 'Force run, independent of new commits'
required: false
default: 'false'
schedule:
- cron: '33 1 * * *'
jobs:
# Check if new commits were added since the last time this workflow ran.
# The Github cache is used for this, using the SHA as the key.
check_commits:
name: Check for new commits
runs-on: ubuntu-latest
outputs:
build: ${{ steps.cache-sha.outputs.cache-hit == false }}
steps:
- name: Cache marker for latest commit
uses: actions/cache@v3
id: cache-sha
with:
key: sha-${{ github.sha }}
path: timestamp.txt
- name: Register latest commit
if: ${{ steps.cache-sha.outputs.cache-hit == false }}
run: |
echo "Current commit $GITHUB_SHA has no cache hit."
date > timestamp.txt
echo "Build job should be triggered now"
cat timestamp.txt
- name: Stop on no new commit
if: ${{ steps.cache-sha.outputs.cache-hit }}
run: |
echo "Current commit $GITHUB_SHA was already seen."
echo "Build job should be skipped."
[ -f timestamp.txt ] && cat timestamp.txt
# Build Gitblit GO so that it can be packed into a docker image.
# The built tarball is saved as an artefact, it can be downloaded
# by interested parties.
# We could even do better and check if paths of source files changed,
# but that is not that easy, so we build on any commit.
build:
name: build GO
runs-on: ubuntu-latest
needs: check_commits
if: ${{ needs.check_commits.outputs.build == 'true' || github.event.inputs.forced == 'true' }}
steps:
- name: Checkout Gitblit
uses: actions/checkout@v3
with:
submodules: true
- name: Setup Java 8
uses: actions/setup-java@v3
with:
java-version: 8
distribution: 'temurin'
- name: Report Java version
run: |
java -version
javac -version
- name: Build GO with Ant
run: ant buildGO
- name: Save built Gitblit package
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' }}
uses: actions/upload-artifact@v3
with:
name: gitblit-nightly
path: build/target/gitblit-*-SNAPSHOT.tar.gz
# This is a gating job, which checks if the secrets necessary for pushing an image
# to the docker hub are present in the repository. This way this workflow can be
# present in repos which cannot upload to the docker hub.
secret-gate:
name: Gate job checking for docker hub secret
runs-on: ubuntu-latest
needs: build
outputs:
build_docker: ${{steps.check-dh-login.outputs.secrets_present}}
steps:
- name: Check if we have the necessary data for docker
id: check-dh-login
run: |
if [[ -n "${{secrets.DOCKERHUB_GB_TOKEN}}" && -n "${{secrets.DOCKERHUB_GB_USER}}" ]] ; then
echo "secrets_present=true" >> $GITHUB_OUTPUT
else
echo "No Docker Hub login data found. Skipping Docker."
fi
# Only if the gating job signals success will this job run and build and push the docker image
# built for the current snapshot version of Gitblit.
docker:
name: Build and push nightly docker image
runs-on: ubuntu-latest
if: needs.secret-gate.outputs.build_docker == 'true' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop')
needs: secret-gate
env:
GH_ORG: gitblit-org
GITBLIT_VERSION: SNAPSHOT
steps:
- name: Checkout gitblit-docker
uses: actions/checkout@v3
with:
repository: ${{ env.GH_ORG }}/gitblit-docker
ref: master
fetch-depth: 2
- name: Download Gitblit nightly build
uses: actions/download-artifact@v3
id: get-gb
with:
name: gitblit-nightly
- name: Extract snapshot version
id: gb-version
run: |
for file in $(ls -1 ${{steps.get-gb.outputs.download-path}}) ; do
if [[ "$file" = gitblit-*.gz ]] ; then gbver=$file ; fi
done
gbver=${gbver%.tar.gz}
gbver=${gbver##*gitblit-}
echo "Version detected: $gbver"
echo "GITBLIT_VERSION=$gbver" >> "${GITHUB_ENV}"
echo "gb-version=$gbver" >> $GITHUB_OUTPUT
- name: Generate Dockerfile for snapshot image
run: |
generate/generate_dockerfile.sh -v ${{ steps.gb-version.outputs.gb-version }} > generate/Dockerfile
echo "BUILD_DATE=$(date +%Y-%m-%dT%H:%M:%S)" >> "${GITHUB_ENV}"
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_GB_USER }}
password: ${{ secrets.DOCKERHUB_GB_TOKEN }}
- name: Build snapshot docker image
uses: docker/build-push-action@v3
with:
file: generate/Dockerfile
context: .
load: true
tags: gitblit/gitblit:nightly
labels: |
org.label-schema.vcs-ref=${{github.sha}}
org.label-schema.build-date=${{env.BUILD_DATE}}
org.opencontainers.image.revision=${{ env.GITBLIT_GIT_SHA }}
org.opencontainers.image.created=${{ env.BUILD_DATE }}
- name: Install Goss for testing the docker image
uses: e1himself/goss-installation-action@v1.0.4
with:
version: 'v0.3.16'
- name: Test docker container - normal mode
env:
GOSS_WAIT_OPTS: "-r 15s -s 5s > /dev/null"
run: |
dgoss run -p 8080:8080 -p 8443:8443 gitblit/gitblit:nightly
- name: Test docker container - bind mount
env:
GOSS_WAIT_OPTS: "-r 15s -s 5s > /dev/null"
run: |
mkdir gitblit-data
mkdir gitblit-data/etc
echo "This should not be overwritten" > gitblit-data/etc/gitblit.properties
echo "include = gitblit-docker.properties" >> gitblit-data/etc/gitblit.properties
sed -e '/mode: / d' -e '/group: / d' goss.yaml > gitblit-data/goss.yaml
cp goss_wait.yaml gitblit-data/
GOSS_FILES_PATH=gitblit-data dgoss run -p 8080:8080 -p 8443:8443 -v "$PWD/gitblit-data":/var/opt/gitblit gitblit/gitblit:nightly
[ -d gitblit-data/srv/git ] || exit 1
[ -f gitblit-data/etc/defaults.properties ] || exit 1
grep --quiet "This should not be overwritten" gitblit-data/etc/gitblit.properties || exit 1
sudo rm -rf gitblit-data
- name: Test docker container - tmpfs
env:
GOSS_WAIT_OPTS: "-r 15s -s 5s > /dev/null"
run: |
dgoss run -p 8080:8080 -p 8443:8443 --tmpfs /var/opt/gitblit/temp gitblit/gitblit:nightly
# Delete the artifact unless this is the official Gitblit repo
- uses: geekyeggo/delete-artifact@v2
if: ${{ github.repository != 'gitblit-org/gitblit' }}
with:
name: gitblit-nightly
failOnError: false
- name: Push docker image to registry
uses: docker/build-push-action@v3
with:
file: generate/Dockerfile
context: .
push: true
tags: gitblit/gitblit:nightly
labels: |
org.label-schema.vcs-ref=${{github.sha}}
org.label-schema.build-date=${{env.BUILD_DATE}}