Skip to content

Push to Container Registry #41

Push to Container Registry

Push to Container Registry #41

name: Push to Container Registry
# only trigger on pull request closed events
on:
pull_request:
types: [ closed ]
workflow_dispatch:
branches: [ master ]
jobs:
push_image:
# this job will only run if the PR has been merged
if: (github.event.pull_request.merged == true) || (github.event_name == 'workflow_dispatch')
runs-on: ubuntu-20.04
steps:
- name: Check the Pull Request
if: github.event.pull_request != null
run: echo "Event '${{ github.event_name }}' - PR ${{ github.event.pull_request.number }} has been merged"
- name: Check for Manual Launch
if: github.event_name == 'workflow_dispatch'
run: echo "Event '${{ github.event_name }}' - Manual Push to Registry"
- name: Install Git Tools
run: |
perl --version
sudo apt-get update
sudo apt-get -y install git cpanminus python3-yaml python3-git
cpanm --local-lib=~/perl5 local::lib
eval $(perl -Mlocal::lib -I ~/perl5/lib/perl5/)
cpanm -n Process::SubProcess
echo "Process::SubProcess Command:"
which run_subprocess.pl || true
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.RELEASE_PUBLISH_TOKEN }}
- name: Requested Version
id: requested_version
run: |
version_result=`scripts/version_matrix.py check`
echo $version_result
requested_version=`echo "$version_result" | sed -n 2p`
if [ -z "$requested_version" ]; then requested_version="latest"; fi;
echo "version=$requested_version" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.5.0
# Build the Docker Image Build with new stable Rust Version
- name: Build the Image
if: steps.requested_version.outputs.version == 'latest'
run: |
echo "Build the Docker Image"
docker build -t rust_builder .
# Build the Docker Image Build with new stable Rust Version
- name: Build the Image
if: steps.requested_version.outputs.version != 'latest'
run: |
echo "Build the Docker Image"
docker build -t rust_builder:${{steps.requested_version.outputs.version}} . --build-arg="RUST_VERSION=${{steps.requested_version.outputs.version}}"
# Show Compiler Version
- name: Show Compiler Version
id: rust_version
run: |
rust_version_info=`docker run -t rust_builder:${{steps.requested_version.outputs.version}} bash -c "rustc --version"`
rust_version=`echo "$rust_version_info" | awk '{print $2}'`
echo "* Rust Compiler Version:" | tee > VERSION
echo "$rust_version | $rust_version_info" | tee >> VERSION
echo "version_info=$rust_version_info" >> $GITHUB_OUTPUT
echo "version=$rust_version" >> $GITHUB_OUTPUT
- name: Check Repository for Rust Version Tag
id: git_tag
run: |
git fetch --tags
tag_label=`git tag -l "v${{ steps.rust_version.outputs.version }}"`
if [ -z $tag_label ]; then tag_label="v${{ steps.rust_version.outputs.version }}"; tag_exists=0; else tag_exists=1; fi;
echo "git - tag: '$tag_label'; exists: '$tag_exists'"
echo "tag=$tag_label" >> $GITHUB_OUTPUT
echo "exists=$tag_exists" >> $GITHUB_OUTPUT
# Version file might exist on retry
- name: Tag the Repository with Rust Version Tag
id: git_tag_set
if: steps.git_tag.outputs.exists == 0
run: |
echo "git - tag: '${{ steps.git_tag.outputs.tag }}'; exists: '${{ steps.git_tag.outputs.exists }}'"
git checkout master
author_res=`git log -1 | grep -i author | sed -re 's/^[^:]+: ([^<]+) <([^>]+)>.*/\1|\2/i'`
echo -e "Commit Author:\n$author_res"
if [ -z "$author_res" ]; then echo "could not find GIT COMMIT AUTHOR"; exit 1; fi;
author_user=`echo "$author_res" | cut -d"|" -f1`
author_email=`echo "$author_res" | cut -d"|" -f2`
git config user.name "$author_user"
git config user.email "$author_email"
save_result=`scripts/version_matrix.py save ${{ steps.rust_version.outputs.version }}`
echo "$save_result"
modified=`echo "$save_result" | sed -re "s/.*save versions: '([0-9]+)' versions.*/\1/i"`
if [ "$modified" == "1" ]; then git add rust-version_matrix.yml; fi;
git add VERSION
git commit -m "Added new Rust Compiler Version: ${{ steps.rust_version.outputs.version }}"
echo "Show commit on 'master':"
git show
git push || true
git tag -a "${{ steps.git_tag.outputs.tag }}" -m "Update Image '${{ steps.git_tag.outputs.tag }}' with Rust Compiler Version: ${{ steps.package_version.outputs.version_info }} "
git push origin ${{ steps.git_tag.outputs.tag }}
# Show Compiler Version
- name: Set Compiler Version Tag
id: image_tag
if: (steps.git_tag.outputs.exists == 0) && (steps.requested_version.outputs.version == 'latest')
run: |
echo "rustc ver: '${{ steps.rust_version.outputs.version }}'"
docker tag rust_builder rust_builder:${{ steps.git_tag.outputs.tag }}
- name: Extract metadata (tags, labels) for Docker
id: image_meta
if: steps.git_tag.outputs.exists == 0
uses: docker/metadata-action@v4.3.0
with:
images: ghcr.io/${{ github.repository }}
tags: |
# use custom value instead of git tag
type=semver,pattern={{version}},value=v${{ steps.rust_version.outputs.version }}
# Show Image Meta Data
- name: Show Image Tags and Labels
if: steps.git_tag.outputs.exists == 0
run: |
echo "* Image Tags:"
echo "${{ steps.image_meta.outputs.tags }}"
echo "* Image Labels:"
echo "${{ steps.image_meta.outputs.labels }}"
echo "* Image Inspection:"
docker inspect rust_builder:${{steps.requested_version.outputs.version}}
- name: Login to GitHub Container Registry
if: steps.git_tag.outputs.exists == 0
uses: docker/login-action@v2.1.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.IMAGE_PUBLISH_AUTH_TOKEN }}
- name: Build and push Docker image
if: steps.git_tag.outputs.exists == 0
uses: docker/build-push-action@v4.0.0
with:
context: .
push: true
tags: ${{ steps.image_meta.outputs.tags }}
labels: ${{ steps.image_meta.outputs.labels }}
secrets: |
GIT_AUTH_TOKEN=${{ secrets.IMAGE_PUBLISH_AUTH_TOKEN }}