From 1881e0a1f32df4f8b242535a8d8ba8efe11bd70d Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Fri, 17 Nov 2023 00:44:15 +0100 Subject: [PATCH 01/13] Just get the first found patch-level for Debian WinCC OA 3.19 --- scripts/download.sh | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/scripts/download.sh b/scripts/download.sh index 572a8ff..cc8a3ae 100644 --- a/scripts/download.sh +++ b/scripts/download.sh @@ -1,21 +1,37 @@ #!/bin/bash -# File containing the HTML content -HTML_FILE="Downloads.html" - +# Files containing the HTML content +HTML1_FILE="login.html" +HTML2_FILE="all319platforms.html" +HTML3_FILE="debiandownload.html" # Define the base URL BASE_URL="https://www.winccoa.com" OUTPUT_FILE="WinCC_OA.zip" -PATCH_NUM="p007" +echo "Login to ${BASE_URL}" +curl -o "$HTML1_FILE" -c cookie.txt -d "user=${USERNAME}&pass=${PASSWORD}&logintype=login" -X POST "${BASE_URL}/index.html?tx_felogin_login%5Baction%5D=login&tx_felogin_login%5Bcontroller%5D=Login" + +echo "Open main Downloadpage" +curl -o "$HTML2_FILE" -b cookie.txt "${BASE_URL}/downloads/category/wincc-oa-319.html" + +echo "Search for download link" +LINK=$(awk -v RS="" ' + /WinCC OA 3.19/ && /Debian 11 \(Bullseye\)/ && !/arm64/ { + match($0, /href="([^"]+)"/, arr) + if (arr[1] != "") { + print arr[1] + exit + } + } +' $HTML2_FILE | sed 's/\&/\&/g') -curl -o "$HTML_FILE" -c cookie.txt -d "user=${USERNAME}&pass=${PASSWORD}&logintype=login" -X POST "${BASE_URL}/index.html?tx_felogin_login%5Baction%5D=login&tx_felogin_login%5Bcontroller%5D=Login" +echo "Opening link: ${BASE_URL}/${LINK}" -curl -o "$HTML_FILE" -b cookie.txt "${BASE_URL}/downloads/detail/wincc-oa-319-${PATCH_NUM}-debian-11-bullseye.html" +curl -o "$HTML3_FILE" -b cookie.txt "${BASE_URL}/${LINK}" # Extract the relative URL -RELATIVE_URL=$(grep "Download ZIP File" $HTML_FILE | grep -v "arm64" | sed -n 's/.*href="\([^"]*\).*/\1/p' | sed 's/\&/\&/g') +RELATIVE_URL=$(grep "Download ZIP File" $HTML3_FILE | grep -v "arm64" | sed -n 's/.*href="\([^"]*\).*/\1/p' | sed 's/\&/\&/g') # Create the full URL FULL_URL="${BASE_URL}${RELATIVE_URL}" From a78169958250d521d190beca679769ef1940ad1e Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Tue, 21 Nov 2023 23:55:31 +0100 Subject: [PATCH 02/13] Change user and password variables and output file with original name --- scripts/download.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/download.sh b/scripts/download.sh index cc8a3ae..a179cda 100644 --- a/scripts/download.sh +++ b/scripts/download.sh @@ -10,7 +10,7 @@ BASE_URL="https://www.winccoa.com" OUTPUT_FILE="WinCC_OA.zip" echo "Login to ${BASE_URL}" -curl -o "$HTML1_FILE" -c cookie.txt -d "user=${USERNAME}&pass=${PASSWORD}&logintype=login" -X POST "${BASE_URL}/index.html?tx_felogin_login%5Baction%5D=login&tx_felogin_login%5Bcontroller%5D=Login" +curl -o "$HTML1_FILE" -c cookie.txt -d "user=${ETM_USERNAME}&pass=${ETM_PASSWORD}&logintype=login" -X POST "${BASE_URL}/index.html?tx_felogin_login%5Baction%5D=login&tx_felogin_login%5Bcontroller%5D=Login" echo "Open main Downloadpage" curl -o "$HTML2_FILE" -b cookie.txt "${BASE_URL}/downloads/category/wincc-oa-319.html" @@ -40,6 +40,9 @@ echo "Downloading $FULL_URL to $OUTPUT_FILE" # Specify the output filename # Download the file with verbose output -curl -o "$OUTPUT_FILE" -b cookie.txt "$FULL_URL" +# curl -o "$OUTPUT_FILE" -b cookie.txt "$FULL_URL" + +# Download using original filename +curl -O -J -b cookie.txt "$FULL_URL" echo "Downloaded to $OUTPUT_FILE" From 2c4269bb07a395e2c15c5b8dd4926af04209964e Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Tue, 21 Nov 2023 23:56:08 +0100 Subject: [PATCH 03/13] Add base files to generate Docker images --- build-docker/Dockerfile_install | 35 ++++++++++++++++++++++++++++ build-docker/docker-compose.yml | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 build-docker/Dockerfile_install create mode 100644 build-docker/docker-compose.yml diff --git a/build-docker/Dockerfile_install b/build-docker/Dockerfile_install new file mode 100644 index 0000000..39359cc --- /dev/null +++ b/build-docker/Dockerfile_install @@ -0,0 +1,35 @@ +# To change the base image please pass the desired value +# during the docker build, for example: +# docker build --build-arg BASE_IMAGE=customdockerregistry/baseimage:latest -t winccoa319 . +ARG BASE_IMAGE=winccoaprepare:temp +# Pass ARCH as prefix to BASE_IMAGE to explicitly set the used architecture. +# The image needs to be available under the resulting FROM argument and your +# environment needs to be able to run the architecture from the image +# docker build --build-arg ARCH=arm64v8/ -t arm64v8/winccoa319 . +ARG ARCH= +FROM ${ARCH}${BASE_IMAGE} as addedrepo + +RUN echo 'deb [trusted=yes] http://repo-server/ /' | sudo tee -a /etc/apt/sources.list.d/build.list > /dev/null && \ + sudo apt-get update + +FROM addedrepo AS winccoabase +RUN sudo apt-get -y install winccoa-\*-base + +FROM winccoabase AS winccoaapi +RUN sudo apt-get -y install winccoa-\*-apicpp + +FROM winccoabase AS winccoaserver +RUN sudo apt-get -y install winccoa-\*-baseserver + +FROM winccoaserver AS winccoauiserver +RUN sudo apt-get -y install winccoa-\*-baseui winccoa-\*-baseshortcuts winccoa-\*-desktopuiserver + +# docker network create winccoarepo +# docker compose up -d +# docker compose wait create-repo +# original Dockerfile needs to disable COPY and package installation, best to replace codemeter with codemeter-lite +# DOCKER_BUILDKIT=0 docker build --network=winccoarepo -t winccoaprepare:temp . +# DOCKER_BUILDKIT=0 docker build --no-cache --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoaapi --tag winccoa/3.19.7:api -f Dockerfile_install . +# DOCKER_BUILDKIT=0 docker build --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoaserver --tag winccoa/3.19.7:baseserver -f Dockerfile_install . +# docker compose down +# docker network rm winccoarepo \ No newline at end of file diff --git a/build-docker/docker-compose.yml b/build-docker/docker-compose.yml new file mode 100644 index 0000000..4925318 --- /dev/null +++ b/build-docker/docker-compose.yml @@ -0,0 +1,41 @@ +version: "3" +services: + create-repo: + image: debian:bullseye-slim + restart: no + command: ['bash', '-c', 'apt-get update && apt-get -y install dpkg-dev gzip && cd /work/ && dpkg-scanpackages -m . | gzip > Packages.gz'] + volumes: + - ../data/:/work/ + repo-server: + image: nginx:latest + expose: + - "80" + volumes: + - ../data/:/usr/share/nginx/html/ +# - ./file-listing.conf:/etc/nginx/conf.d/default.conf + networks: + - winccoarepo + depends_on: + - create-repo + +# _winccoa_build: +# image: winccoa320 +# command: ['echo', 'build completed'] # any linux command which directly terminates. +# build: + #context: winccoa/. +# network: repo-server +# args: +# BASE_IMAGE: artifactory.etm.at:8445/docker-winccoa/runtime/debian:bullseye-linux-amd64 # to speedup build a bit we use an image which already has most dependencies installed +# BASE_IMAGE: artifactory.etm.at:8445/docker-winccoa/build/debian:bullseye # for debugging we need to use a developer image +# volumes: +# - ../data/Dockerfile:/work/ + +networks: + winccoarepo: + driver: bridge + external: true + name: winccoarepo + + +# docker buildx create --use --name winccoabuilder --driver docker-container --driver-opt "network=winccoarepo" +# docker buildx \ No newline at end of file From 4b0a2ad2e2759e8e8486c2ee49c65cd1e1c57c84 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Wed, 22 Nov 2023 17:15:54 +0100 Subject: [PATCH 04/13] Add patch script for Dockerfile provided from WinCC OA --- scripts/patchDockerfile.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scripts/patchDockerfile.sh diff --git a/scripts/patchDockerfile.sh b/scripts/patchDockerfile.sh new file mode 100644 index 0000000..c0e3c56 --- /dev/null +++ b/scripts/patchDockerfile.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Check if a file path is provided +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +# File paths +original_dockerfile="$1" +backup_dockerfile="${original_dockerfile}.backup" + +# Create a backup of the original Dockerfile +cp "$original_dockerfile" "$backup_dockerfile" + +# Apply changes +sed -i '/^COPY \*.deb/s/^/#/' "$original_dockerfile" +sed -i '/^RUN find \/tmp\/deb\//s/^/#/' "$original_dockerfile" +sed -i '/^\s*-name \\\*.deb/s/^/#/' "$original_dockerfile" +sed -i '/^\s*-not -name/s/^/#/' "$original_dockerfile" +sed -i '/^\s*-exec apt-get install/s/^/#/' "$original_dockerfile" +sed -i '/^\s*apt-get clean/s/^/#/' "$original_dockerfile" From 971b5068cdbf2f35ff23db43d77c411c66a14a4b Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Wed, 22 Nov 2023 17:39:49 +0100 Subject: [PATCH 05/13] Add first version of build pipeline --- .github/workflows/generate-winccoa-image.yml | 93 ++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .github/workflows/generate-winccoa-image.yml diff --git a/.github/workflows/generate-winccoa-image.yml b/.github/workflows/generate-winccoa-image.yml new file mode 100644 index 0000000..8b4a496 --- /dev/null +++ b/.github/workflows/generate-winccoa-image.yml @@ -0,0 +1,93 @@ +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: Unzip dataPrepare data for Docker image build + 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: 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 + working-directory: ./build-docker + run: | + DOCKER_BUILDKIT=0 docker build --network=winccoarepo -t winccoaprepare:temp . + DOCKER_BUILDKIT=0 docker build --no-cache --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoaapi --tag agruberetm/winccoa/3.19.7:api -f Dockerfile_install . + DOCKER_BUILDKIT=0 docker build --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoaserver --tag agruberetm/winccoa/3.19.7:baseserver -f Dockerfile_install . + + - name: Docker build teardown + working-directory: ./build-docker + run: | + docker compose down + docker network rm winccoarepo + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Docker push + run: | + docker push agruberetm/winccoa/3.19.7:api + docker push agruberetm/winccoa/3.19.7:baseserver From 18a1b25ae2f590e9c06c7e9ca707b4c13705f750 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Wed, 22 Nov 2023 17:46:16 +0100 Subject: [PATCH 06/13] Set permissions to scripts --- scripts/download.sh | 0 scripts/patchDockerfile.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/download.sh mode change 100644 => 100755 scripts/patchDockerfile.sh diff --git a/scripts/download.sh b/scripts/download.sh old mode 100644 new mode 100755 diff --git a/scripts/patchDockerfile.sh b/scripts/patchDockerfile.sh old mode 100644 new mode 100755 From 2023efbfca90228555e0891610b517711bd61632 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Wed, 22 Nov 2023 17:56:43 +0100 Subject: [PATCH 07/13] Change image name, temporary hardcoded --- .github/workflows/generate-winccoa-image.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/generate-winccoa-image.yml b/.github/workflows/generate-winccoa-image.yml index 8b4a496..a36fb1b 100644 --- a/.github/workflows/generate-winccoa-image.yml +++ b/.github/workflows/generate-winccoa-image.yml @@ -48,7 +48,7 @@ jobs: ETM_PASSWORD: ${{ secrets.ETM_PASSWORD }} run: scripts/download.sh - - name: Unzip dataPrepare data for Docker image build + - name: Unzip data run: | mkdir data && cd data && \ unzip ../*.zip @@ -68,12 +68,17 @@ jobs: # wait until repo data is generated docker compose wait create-repo - - name: Docker build + - name: Docker build preparation image working-directory: ./build-docker run: | DOCKER_BUILDKIT=0 docker build --network=winccoarepo -t winccoaprepare:temp . - DOCKER_BUILDKIT=0 docker build --no-cache --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoaapi --tag agruberetm/winccoa/3.19.7:api -f Dockerfile_install . - DOCKER_BUILDKIT=0 docker build --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoaserver --tag agruberetm/winccoa/3.19.7:baseserver -f Dockerfile_install . + + - name: Docker build WinCC OA images + working-directory: ./build-docker + run: | + DOCKER_BUILDKIT=0 docker build --network=winccoarepo -t winccoaprepare:temp . + DOCKER_BUILDKIT=0 docker build --no-cache --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoaapi --tag agruberetm/winccoa-3.19.7:api -f Dockerfile_install . + DOCKER_BUILDKIT=0 docker build --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoaserver --tag agruberetm/winccoa-3.19.7:baseserver -f Dockerfile_install . - name: Docker build teardown working-directory: ./build-docker @@ -89,5 +94,5 @@ jobs: - name: Docker push run: | - docker push agruberetm/winccoa/3.19.7:api - docker push agruberetm/winccoa/3.19.7:baseserver + docker push agruberetm/winccoa-3.19.7:api + docker push agruberetm/winccoa-3.19.7:baseserver From f3bdf3b1bd272aa35020211cec8c158f3acfa7f1 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Fri, 24 Nov 2023 00:32:14 +0100 Subject: [PATCH 08/13] Output real filename in download script --- scripts/download.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/download.sh b/scripts/download.sh index a179cda..d0c1e4b 100755 --- a/scripts/download.sh +++ b/scripts/download.sh @@ -7,8 +7,6 @@ HTML3_FILE="debiandownload.html" # Define the base URL BASE_URL="https://www.winccoa.com" -OUTPUT_FILE="WinCC_OA.zip" - echo "Login to ${BASE_URL}" curl -o "$HTML1_FILE" -c cookie.txt -d "user=${ETM_USERNAME}&pass=${ETM_PASSWORD}&logintype=login" -X POST "${BASE_URL}/index.html?tx_felogin_login%5Baction%5D=login&tx_felogin_login%5Bcontroller%5D=Login" @@ -36,13 +34,12 @@ RELATIVE_URL=$(grep "Download ZIP File" $HTML3_FILE | grep -v "arm64" | sed -n ' # Create the full URL FULL_URL="${BASE_URL}${RELATIVE_URL}" -echo "Downloading $FULL_URL to $OUTPUT_FILE" +echo "Downloading $FULL_URL" # Specify the output filename # Download the file with verbose output +# OUTPUT_FILE="WinCC_OA.zip" # curl -o "$OUTPUT_FILE" -b cookie.txt "$FULL_URL" # Download using original filename -curl -O -J -b cookie.txt "$FULL_URL" - -echo "Downloaded to $OUTPUT_FILE" +curl -O -J -b cookie.txt "$FULL_URL" -w "%{filename_effective}" From 3585bb908524205d47e4a5d7889810b0c9c27f58 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Fri, 24 Nov 2023 00:33:14 +0100 Subject: [PATCH 09/13] Get version number from filename and use a more elegant approach for naming an build-push workflow --- .github/workflows/generate-winccoa-image.yml | 60 ++++++++++++++------ 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/.github/workflows/generate-winccoa-image.yml b/.github/workflows/generate-winccoa-image.yml index a36fb1b..4b1fbe1 100644 --- a/.github/workflows/generate-winccoa-image.yml +++ b/.github/workflows/generate-winccoa-image.yml @@ -48,6 +48,35 @@ jobs: 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 && \ @@ -60,6 +89,12 @@ jobs: # 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: | @@ -71,28 +106,21 @@ jobs: - name: Docker build preparation image working-directory: ./build-docker run: | - DOCKER_BUILDKIT=0 docker build --network=winccoarepo -t winccoaprepare:temp . + DOCKER_BUILDKIT=0 docker build --no-cache --network=winccoarepo -t winccoaprepare:temp . - - name: Docker build WinCC OA images + - name: Docker build and push images working-directory: ./build-docker run: | - DOCKER_BUILDKIT=0 docker build --network=winccoarepo -t winccoaprepare:temp . - DOCKER_BUILDKIT=0 docker build --no-cache --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoaapi --tag agruberetm/winccoa-3.19.7:api -f Dockerfile_install . - DOCKER_BUILDKIT=0 docker build --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoaserver --tag agruberetm/winccoa-3.19.7:baseserver -f Dockerfile_install . + 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 - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USER }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Docker push - run: | - docker push agruberetm/winccoa-3.19.7:api - docker push agruberetm/winccoa-3.19.7:baseserver From e15af6647ee9eb4c6b61558e10b15e4cec59c792 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Fri, 24 Nov 2023 00:49:34 +0100 Subject: [PATCH 10/13] Use DOCKER_IMAGE env var for Docker image basename, fix set-output warning --- .github/workflows/generate-winccoa-image.yml | 23 +++++++++++--------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/generate-winccoa-image.yml b/.github/workflows/generate-winccoa-image.yml index 4b1fbe1..457990c 100644 --- a/.github/workflows/generate-winccoa-image.yml +++ b/.github/workflows/generate-winccoa-image.yml @@ -24,7 +24,7 @@ jobs: else ENV_NAME=staging fi - echo "::set-output name=env_name::${ENV_NAME}" + echo "env_name=${ENV_NAME}" >> $GITHUB_OUTPUT - name: Chosen environment run: echo "Environment used ${{ steps.branch_check.outputs.env_name }}" @@ -57,8 +57,8 @@ jobs: [[ $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]} + patch_version=$(echo ${BASH_REMATCH[3]} | sed 's/^0*//') # Remove leading zeros + revision=${BASH_REMATCH[4]#\.} # Remove leading dot from the revision if [ "$revision" != "0" ] && [ ! -z "$revision" ]; then version_string="$major_version.$minor_version.$patch_version.$revision" @@ -66,11 +66,11 @@ jobs: 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}" + echo "major_version=${major_version}" >> $GITHUB_OUTPUT + echo "minor_version=${minor_version}" >> $GITHUB_OUTPUT + echo "patch_version=${patch_version}" >> $GITHUB_OUTPUT + echo "revision=${revision}" >> $GITHUB_OUTPUT + echo "version=${version_string}" >> $GITHUB_OUTPUT else echo "No ZIP file found" @@ -111,13 +111,16 @@ jobs: - name: Docker build and push images working-directory: ./build-docker run: | - for target in api server; do + # specify targets from Dockerfile_install here + for target in api server uiserver; do tag_suffix=${target} - image_name="agruberetm/winccoa:v${{ steps.get_version.outputs.version }}-${tag_suffix}" + image_name="${DOCKER_IMAGE}: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 + env: + DOCKER_IMAGE: ${{ secrets.DOCKER_IMAGE }} - name: Docker build teardown working-directory: ./build-docker From 52d420cce898a44011f3e16ee2a06ed6e9a7bc71 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Fri, 24 Nov 2023 00:56:29 +0100 Subject: [PATCH 11/13] Bugfix and cosmetics --- .github/workflows/generate-winccoa-image.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/generate-winccoa-image.yml b/.github/workflows/generate-winccoa-image.yml index 457990c..f43a7d0 100644 --- a/.github/workflows/generate-winccoa-image.yml +++ b/.github/workflows/generate-winccoa-image.yml @@ -24,11 +24,11 @@ jobs: else ENV_NAME=staging fi + + echo "Chosen environment: ${ENV_NAME}" + echo "env_name=${ENV_NAME}" >> $GITHUB_OUTPUT - - - name: Chosen environment - run: echo "Environment used ${{ steps.branch_check.outputs.env_name }}" - + outputs: env_name: ${{ steps.branch_check.outputs.env_name }} @@ -66,6 +66,8 @@ jobs: version_string="$major_version.$minor_version.$patch_version" fi + echo "Version info found: ${version_string}" + echo "major_version=${major_version}" >> $GITHUB_OUTPUT echo "minor_version=${minor_version}" >> $GITHUB_OUTPUT echo "patch_version=${patch_version}" >> $GITHUB_OUTPUT @@ -120,7 +122,7 @@ jobs: docker push ${image_name} done env: - DOCKER_IMAGE: ${{ secrets.DOCKER_IMAGE }} + DOCKER_IMAGE: ${{ vars.DOCKER_IMAGE }} - name: Docker build teardown working-directory: ./build-docker From dff69f977f12ef5e81b63e38e169aab1c29e5120 Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Fri, 24 Nov 2023 16:37:16 +0100 Subject: [PATCH 12/13] Small corrections and remove duplicate code --- .github/workflows/generate-winccoa-image.yml | 6 +++--- build-docker/Dockerfile_install | 10 ---------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/.github/workflows/generate-winccoa-image.yml b/.github/workflows/generate-winccoa-image.yml index f43a7d0..7623355 100644 --- a/.github/workflows/generate-winccoa-image.yml +++ b/.github/workflows/generate-winccoa-image.yml @@ -13,8 +13,8 @@ jobs: runs-on: ubuntu-latest steps: - - name: Some check on branch - id: branch_check + - name: Define the used environment + id: env_check run: | ENV_NAME=staging if [[ "${{ github.event_name }}" == "release" ]]; then @@ -30,7 +30,7 @@ jobs: echo "env_name=${ENV_NAME}" >> $GITHUB_OUTPUT outputs: - env_name: ${{ steps.branch_check.outputs.env_name }} + env_name: ${{ steps.env_check.outputs.env_name }} generate-winccoa-image: needs: [get_environment] diff --git a/build-docker/Dockerfile_install b/build-docker/Dockerfile_install index 39359cc..a30e48a 100644 --- a/build-docker/Dockerfile_install +++ b/build-docker/Dockerfile_install @@ -23,13 +23,3 @@ RUN sudo apt-get -y install winccoa-\*-baseserver FROM winccoaserver AS winccoauiserver RUN sudo apt-get -y install winccoa-\*-baseui winccoa-\*-baseshortcuts winccoa-\*-desktopuiserver - -# docker network create winccoarepo -# docker compose up -d -# docker compose wait create-repo -# original Dockerfile needs to disable COPY and package installation, best to replace codemeter with codemeter-lite -# DOCKER_BUILDKIT=0 docker build --network=winccoarepo -t winccoaprepare:temp . -# DOCKER_BUILDKIT=0 docker build --no-cache --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoaapi --tag winccoa/3.19.7:api -f Dockerfile_install . -# DOCKER_BUILDKIT=0 docker build --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoaserver --tag winccoa/3.19.7:baseserver -f Dockerfile_install . -# docker compose down -# docker network rm winccoarepo \ No newline at end of file From d6953f74e0abef9dd64fde5087f11fb87abcd26e Mon Sep 17 00:00:00 2001 From: Andreas Gruber Date: Fri, 24 Nov 2023 16:37:26 +0100 Subject: [PATCH 13/13] Add readme --- README.md | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..45cead4 --- /dev/null +++ b/README.md @@ -0,0 +1,88 @@ +# Documentation for "build-winccoa-docker-image" Repository + +This repository hosts a GitHub Action workflow for +- downloading the current WinCC OA version from winccoa.com and +- generating and uploading Docker images of WinCC OA. + +The workflow is defined in `.github\workflows\generate-winccoa-image.yml`. + +## Setting Up + +### Create environment +By default, for all workflow runs, an environment with the name `staging` is used. + +Create all required environments and adapt the logic in the workflow (`get_environment -> env_check`) if you want to use multiple environments. + +### Required Secrets +- `ETM_USERNAME`: Username for winccoa.com +- `ETM_PASSWORD`: Password for winccoa.com +- `DOCKER_USER`: DockerHub username +- `DOCKER_PASSWORD`: DockerHub password + +### Required environment variables +- `DOCKER_IMAGE`: Name of the Docker image, e.g. `mydockerhubuser/winccoa` + +### Triggering the Workflow +The workflow is triggered on: +- Push to `main`, `release/*`, `develop`, and `develop/*` branches. +- Published releases. + +## Workflow Overview + +### Get Environment +- **Environment Setup**: Gets the desired environment + +### Preparation +- **Download Current WinCC OA Version**: Requires ETM_USERNAME and ETM_PASSWORD secrets for authentication​​ +- **Extract Version Information**: Processes a ZIP filename to determine the WinCC OA version​​ +- **Prepare Data for Docker Image Build**: Involves unzipping data and preparing it for Docker build​​. + +### Docker Image Generation +- **Docker Setup**: Sets up Docker and builds a temporary image +- **Docker Build and Push Images**: Builds and pushes Docker images for different targets +- **Docker Build Teardown**: Tears down the Docker setup post-build​​ + +## Dockerfile Targets and Tags +The `build-docker/Dockerfile_install` includes targets like `api`, `server`, and `uiserver` with the prefix `winccoa`. Each target corresponds to a possible tag of the resulting Docker image. + +The really built targets are defined in the step `Docker build and push images`. + +### Modify or Add New Targets + +1. **Adapt Dockerfile**: Define a new target in `build-docker/Dockerfile_install` in the form of `FROM as winccoa` or modify an existing one +2. **Edit Workflow File**: In the `.github/workflows` directory, open the workflow file `generate-winccoa-image.yml` +3. **Add/Modify Steps**: + - Under the `Docker build and push images` step, modify the list of targets in the for loop include your new target or modify the existing one. + - The default list defines the targets: `api server uiserver` + +### Testing Your Changes +- It is highly recommended testing changes locally if possible, all docker commands can be run locally as well +- Once changes are verified locally, test the changes by triggering the workflow +- Monitor the build process to ensure your changes are correctly built and pushed + +## Example +Given: +- Docker image base name: `mydockerhubuser/winccoa` +- Downloaded WinCC OA filename `WinCC_OA_3.19_linux_debian_x86_64_P007.zip` +- Extracted version: `3.19.7` +- List of targets: `api server uiserver` + +Resulting Docker image names: +- `mydockerhubuser/winccoa:v3.19.7-api` from target `winccoaapi` +- `mydockerhubuser/winccoa:v3.19.7-server` from target `winccoaserver` +- `mydockerhubuser/winccoa:v3.19.7-uiserver` from target `winccoauiserver` + +These images are built and pushed to DockerHub using the provided credentials. + +## Contributing + +Your contributions play a pivotal role in enhancing the open-source community, making it a hub for learning, inspiration, and innovation. Every contribution, big or small, is deeply appreciated. + +**Steps to Contribute**: +1. Fork the Project. +2. Create your Feature Branch: `git checkout -b feature/YourFeatureName`. +3. Commit your Changes: `git commit -m 'Describe your change'`. +4. Push to the Branch: `git push origin feature/YourFeatureName`. +5. Open a Pull Request. + +For suggestions or enhancements, either submit a pull request or open an issue with the "enhancement" tag. If you find value in this project, kindly star it. Your support means a lot to me! \ No newline at end of file