build-container #152
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build CI Container | |
on: | |
repository_dispatch: | |
types: [build-container] | |
workflow_dispatch: | |
push: | |
branches: | |
- "*" | |
- "!main" | |
jobs: | |
build-container: | |
runs-on: ubuntu-latest | |
container: hashicorp/packer:1.11 | |
env: | |
ZEPBEN_GPG_KEY: ${{ secrets.ZEPBEN_GPG_KEY }} | |
MAVEN_SETTINGS: ${{ secrets.MAVEN_SETTINGS }} | |
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} | |
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} | |
GPG_KEY_ID: ${{ secrets.GPG_KEY_ID }} | |
GPG_KEY_PASSWORD: ${{ secrets.GPG_KEY_PASSWORD }} | |
DOCKER_HUB_ACCESS_TOKEN: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install deps | |
run: | | |
apk add libxml2-utils docker | |
- name: Packer Version | |
run: | | |
packer version | |
- name: Create docker container | |
run: | | |
# Scripts to copy dependencies from dependencyManagement | |
cp for-ci-build-image/deps-pom-template.xml deps-pom.xml | |
version=$(cat pom.xml | sed 's/xmlns.*=".*"//g' | xmllint --xpath '/project/version/text()' -) | |
sed -i "s/{{version}}/$version/g" deps-pom.xml | |
deps=$(cat pom.xml | sed 's/xmlns.*=".*"//g' | xmllint --xpath '/project/dependencyManagement/dependencies/dependency' -) | |
deps=$(echo $deps | sed 's/\//\\\//g; s/ /\\n/g') | |
ln=$(cat deps-pom.xml | grep -n "<dependencies>" | cut -d':' -f1) | |
ln=$((ln + 1)) | |
sed -i "$ln i $deps" deps-pom.xml | |
# Scripts to copy plugins from pluginManagement | |
plugins=$(cat pom.xml | sed 's/xmlns.*=".*"//g' | xmllint --xpath '/project/build/pluginManagement/plugins/plugin' -) | |
plugins=$(echo $plugins | sed 's/\//\\\//g; s/ /\\n/g') | |
ln=$(cat deps-pom.xml | grep -n "<plugins>" | cut -d':' -f1) | |
ln=$((ln + 1)) | |
sed -i "$ln i $plugins" deps-pom.xml | |
xmllint -format deps-pom.xml > deps-pom-new.xml | |
mv -f deps-pom-new.xml deps-pom.xml | |
ADDITIONAL_ARGS="" | |
if [[ $GITHUB_REF_NAME != "main" ]]; then | |
ADDITIONAL_ARGS="-except docker.push,docker.tag" | |
fi | |
# Handle the base image if provided | |
if [ "z${{ github.event.client_payload.base_image }}" != "z" ]; then | |
# Some label was given via remote call | |
PIPELINE_JAVA_IMAGE="-var base_image=${{ github.event.client_payload.base_image }}" | |
fi | |
# Handle the resulting container labels if provided | |
if [ "z${{ github.event.client_payload.labels }}" != "z" ]; then | |
# the labels come in as "label1 label2" but we need to provide them as | |
# ["label1", "label2"] | |
# So we replace the original values with quoted ones and then wrap in braces | |
# Split the passed values into an array | |
array=(${{ github.event.client_payload.labels }}) | |
# Print every array entry encased by double quotes | |
tags=$(printf "\"%s\"," "${array[@]}") | |
# Construct the list parameter for the container tags | |
IMAGE_TAGS="-var tags=[$tags]" | |
fi | |
cd for-ci-build-image | |
packer init build-container.pkr.hcl | |
packer validate build-container.pkr.hcl | |
packer build -on-error=abort -var dockerhub_user=$DOCKER_HUB_USER -var dockerhub_pw=$DOCKER_HUB_ACCESS_TOKEN $PIPELINE_JAVA_IMAGE $IMAGE_TAGS $ADDITIONAL_ARGS build-container.pkr.hcl | |
shell: bash |