coder-enterprise-images/bin/generate-actions-yaml.sh

64 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
CI_TEMPLATE="bin/ci-template.yaml"
CI_FILE=".github/workflows/ci.yaml"
# Some images need to build before others, everything else can go in any order
ORDERED_IMAGES=("base" "multieditor")
function copyTemplate() {
rm -rf $CI_FILE
echo -e "# File generated by bin/generate-actions-yaml.sh\n$(cat $CI_TEMPLATE)" > $CI_FILE
}
function appendAction() {
image=$1
tag=$2
{
echo " -"
echo " name: Build and push - codercom/enterprise-$image:$tag"
echo " uses: docker/build-push-action@v2"
echo " with:"
echo " context: ./images/$image"
echo " file: ./images/$image/Dockerfile.$tag"
echo " tags: codercom/enterprise-$image:$tag"
echo " push: \${{ github.event_name != 'pull_request' }}"
} >> $CI_FILE
}
function main() {
# Move to top level
pushd $(git rev-parse --show-toplevel)
# Create template yaml
copyTemplate
# Add actions for building each image, maintaining desired image order
image_dirs=($(ls images))
all_images=("${ORDERED_IMAGES[@]}" "${image_dirs[@]}")
seen_images=()
for image in ${all_images[@]}; do
# Skip image if we've already seen it, duplicates come from ORDERED_IMAGES
if [[ "${seen_images[@]}" =~ "${image}" ]]; then
continue
fi
seen_images+=("$image")
# Create action per dockerfile
dockerfiles=$(ls images/$image/Dockerfile*)
for dockerfile in ${dockerfiles}; do
tag=${dockerfile##*.}
appendAction "$image" "$tag"
done
done
# Pop back to original dir
popd
echo "Updated $CI_FILE"
}
main