Get version number from filename and use a more elegant approach for … #4
Workflow file for this run
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: Generate and upload WinCC OA image | |
on: | |
push: | |
branches: [ "main", "release/*", "develop", "develop/*" ] | |
# pull_request: | |
# branches: [ "main", "release/*", "develop", "develop/*" ] | |
release: | |
types: [published] | |
jobs: | |
get_environment: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Some check on branch | |
id: branch_check | |
run: | | |
ENV_NAME=staging | |
if [[ "${{ github.event_name }}" == "release" ]]; then | |
ENV_NAME=staging | |
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
ENV_NAME=staging | |
else | |
ENV_NAME=staging | |
fi | |
echo "::set-output name=env_name::${ENV_NAME}" | |
- name: Chosen environment | |
run: echo "Environment used ${{ steps.branch_check.outputs.env_name }}" | |
outputs: | |
env_name: ${{ steps.branch_check.outputs.env_name }} | |
generate-winccoa-image: | |
needs: [get_environment] | |
runs-on: ubuntu-latest | |
environment: | |
name: ${{ needs.get_environment.outputs.env_name }} | |
steps: | |
- name: Set up Git repository | |
uses: actions/checkout@v3 | |
- name: Download current WinCC OA version | |
env: | |
ETM_USERNAME: ${{ secrets.ETM_USERNAME }} | |
ETM_PASSWORD: ${{ secrets.ETM_PASSWORD }} | |
run: scripts/download.sh | |
- name: Extract version information | |
id: get_version | |
run: | | |
zip_file=$(ls *.zip | head -n 1) | |
if [ -f "$zip_file" ]; then | |
echo "ZIP file found: $zip_file" | |
[[ $zip_file =~ ([0-9]+)\.([0-9]+)_linux_debian_x86_64_P([0-9]+)\.?([0-9]*)\.zip ]] | |
major_version=${BASH_REMATCH[1]} | |
minor_version=${BASH_REMATCH[2]} | |
patch_version=${BASH_REMATCH[3]} | |
revision=${BASH_REMATCH[4]} | |
if [ "$revision" != "0" ] && [ ! -z "$revision" ]; then | |
version_string="$major_version.$minor_version.$patch_version.$revision" | |
else | |
version_string="$major_version.$minor_version.$patch_version" | |
fi | |
echo "::set-output name=major_version::${major_version}" | |
echo "::set-output name=minor_version::${minor_version}" | |
echo "::set-output name=patch_version::${patch_version}" | |
echo "::set-output name=revision::${revision}" | |
echo "::set-output name=version::${version_string}" | |
else | |
echo "No ZIP file found" | |
exit 1 | |
fi | |
- name: Unzip data | |
run: | | |
mkdir data && cd data && \ | |
unzip ../*.zip | |
- name: Prepare data for Docker image build | |
run: | | |
# copy files provided from WinCC OA package for our custom Docker build | |
cp data/docker-entrypoint.sh data/Dockerfile build-docker/ | |
# patch Dockerfile so it does not copy and install the packages, but only does preparation | |
scripts/patchDockerfile.sh build-docker/Dockerfile | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USER }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Docker build setup | |
working-directory: ./build-docker | |
run: | | |
docker network create winccoarepo | |
docker compose up -d | |
# wait until repo data is generated | |
docker compose wait create-repo | |
- name: Docker build preparation image | |
working-directory: ./build-docker | |
run: | | |
DOCKER_BUILDKIT=0 docker build --no-cache --network=winccoarepo -t winccoaprepare:temp . | |
- name: Docker build and push images | |
working-directory: ./build-docker | |
run: | | |
for target in api server; do | |
tag_suffix=${target} | |
image_name="agruberetm/winccoa:v${{ steps.get_version.outputs.version }}-${tag_suffix}" | |
DOCKER_BUILDKIT=0 docker build --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoa${target} --tag ${image_name} -f Dockerfile_install . | |
docker push ${image_name} | |
done | |
- name: Docker build teardown | |
working-directory: ./build-docker | |
run: | | |
docker compose down | |
docker network rm winccoarepo |