Skip to content
# Make Docker images
name: Create Docker images, test main binary, and publish
on:
push:
branches: ['main', 'dev']
env:
REGISTRY: ghcr.io
jobs:
build-test-publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set variables
run: |
echo "${{ github.repository }}" | sed "s/\(.*\)\/.*/ORG_NAME=\1/g" | tee -a $GITHUB_ENV
echo "${{ github.repository }}" | sed "s/.*\/\(.*\)/IMAGE_NAME=\1/g" | tee -a $GITHUB_ENV
echo "github.ref_name: ${{ github.ref_name }}"
VERSION_PREFIX=`echo "${{ github.ref_name }}-" | sed "s/main-$//g"`
echo ${VERSION_PREFIX} | sed "s/\(.*\)/VERSION_PREFIX=\1/g" | tee -a $GITHUB_ENV
# HACK: replace variable in .env
sed -i "s/^VERSION\=\(.*\)/VERSION=${VERSION_PREFIX}\1/g" .env
- name: Docker Compose
run: |
# make a data directory so volume works
mkdir -p data/generated/grid/100m/default
mkdir -p sims
# HACK: docker compose doesn't seem to be using the .env file
source ./.env
echo VERSION=${VERSION}
docker compose --env-file .env build
- name: Test FireSTARR
run: |
docker compose run firestarr /appl/tbd/tbd test dir_test 12
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
# just publish the firestarr container for now
- name: Publish
run: |
IMAGE_ROOT=`docker images | grep -i "^${{ env.IMAGE_NAME }}" | awk '{print $1}' | uniq`
REPO_OUT=${{ env.REGISTRY }}/${{ env.ORG_NAME }}
# convert to lowecase
REPO_OUT=${REPO_OUT,,}
docker images | grep -i "^${IMAGE_ROOT}" | awk '{print $1":"$2}' | grep -i "^${IMAGE_ROOT}:${VERSION_PREFIX}" | xargs -t -I {} docker tag {} ${REPO_OUT}/{}
# if we have a prefix then get rid of "latest" tag so we don't overwrite main's "latest"
if [[ ${VERSION_PREFIX} ]]; then
BRANCH_LATEST=`docker images | grep -i "^${REPO_OUT}/${IMAGE_ROOT}" | awk '{print $1":"$2}' | grep -i "^${REPO_OUT}/${IMAGE_ROOT}:${VERSION_PREFIX}" | sort | head -n1`
docker tag ${BRANCH_LATEST} ${REPO_OUT}/${IMAGE_ROOT}:${VERSION_PREFIX}latest
docker rmi ${IMAGE_ROOT}:latest
fi
docker images | grep -v "<none>" | grep -i "^${REPO_OUT}/${IMAGE_ROOT}" | awk '{print $1":"$2}' | grep -i "^${REPO_OUT}/${IMAGE_ROOT}:${VERSION_PREFIX}" | xargs -t -I {} docker push {}