diff --git a/.github/workflows/build_and_push.yml b/.github/workflows/build_and_push.yml new file mode 100644 index 0000000..4313ba8 --- /dev/null +++ b/.github/workflows/build_and_push.yml @@ -0,0 +1,37 @@ +name: Build and Push Container Image + +on: + push: + tags: ['v*'] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get the latest tag + id: get_tag + run: echo "LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)" >> "$GITHUB_ENV" + + - name: Authenticate to ghcr + run: echo ${{ secrets.GHCR_PAT }} | buildah login --username cjtitus --password-stdin ghcr.io + + - name: Run build script + run: bash buildah_scripts/build.sh + + - name: Push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository }} + # Make sure IMAGE_ID is lowercase for buildah + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + echo $IMAGE_ID + echo "buildah push sst_gui:latest $IMAGE_ID:latest" + buildah push --creds ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }} sst_gui:latest $IMAGE_ID:latest + echo "buildah push sst_gui:latest $IMAGE_ID:$LATEST_TAG" + buildah push sst_gui:latest $IMAGE_ID:$LATEST_TAG \ No newline at end of file diff --git a/buildah_scripts/build.sh b/buildah_scripts/build.sh new file mode 100644 index 0000000..7e85871 --- /dev/null +++ b/buildah_scripts/build.sh @@ -0,0 +1,33 @@ +#! /usr/bin/bash +set -e +set -o xtrace + + +script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +host_package_dir=$(dirname "$script_dir")/src +container_package_dir=/usr/local/src/sst_gui + +version="0.0.1" + +# Check if bluesky:latest image is available locally +if [[ "$(buildah images -q sst:latest)" == "" ]]; then + echo "Image not found locally. Pulling from ghcr.io/nsls-ii-sst..." + buildah pull ghcr.io/nsls-ii-sst/sst:latest +fi + +container=$(buildah from sst) +buildah run $container -- dnf -y install qt5-qtbase-devel +buildah run $container -- conda install -y pyqt +buildah run $container -- pip3 install bluesky_queueserver_api + +buildah copy $container $host_package_dir $container_package_dir +buildah run --workingdir $container_package_dir $container -- pip3 install . + +#buildah config --cmd "sst-gui --config /usr/local/src/sst_gui/sst_gui/test_config.yaml" $container + +buildah unmount $container + +buildah commit $container sst_gui:$version +buildah commit $container sst_gui:latest + +buildah rm $container \ No newline at end of file