forked from jenkins-docs/quickstart-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 1
Fix docker version #473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Fix docker version #473
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f73e04c
fix: ensures the PR will only contain changes to docker-versions.txt …
gounthar 8ef04ff
Apply suggestions from code review
gounthar dcb9592
fix: improve Dockerfile change detection in CI workflow
gounthar 877bb35
fix: update GitHub Actions to skip Docker builds for forked repositories
gounthar 4da3074
fix: update GitHub Actions to skip Docker builds for forked repositories
gounthar d7916fa
fix: update Docker build platforms to support arm64 architecture
gounthar 464d27b
Merge remote-tracking branch 'origin/fix-docker-version' into fix-doc…
gounthar f5bdbb9
fix: update Docker build conditions to check for directory paths
gounthar d1efff5
fix: add check for existing PR before creating Docker version update PR
gounthar d9954fa
fix: remove backticks from Docker version update message
gounthar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,12 +35,6 @@ jobs: | |
| id: changes | ||
| run: echo "files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | tr '\n' ' ')" >> $GITHUB_ENV | ||
|
|
||
| - name: Write Docker versions to file | ||
| # This step writes the Docker and Docker Compose versions to a file | ||
| run: | | ||
| echo "- $(docker --version)" > docker-versions.txt | ||
| echo "- $(docker compose version)" >> docker-versions.txt | ||
|
|
||
| - name: Authenticate GH CLI | ||
| # This step authenticates the GitHub CLI | ||
| run: gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}" | ||
|
|
@@ -50,28 +44,65 @@ jobs: | |
| run: | | ||
| git config --global user.name 'GitHub Action' | ||
| git config --global user.email '[email protected]' | ||
| git checkout -b docker-versions-update | ||
|
|
||
| # Ensure we start from a clean main branch | ||
| git fetch origin main | ||
| git checkout main | ||
| git reset --hard origin/main | ||
|
|
||
| # Create unique branch name to avoid conflicts | ||
| BRANCH_NAME="docker-versions-update-$(date +%s)" | ||
| git checkout -b "$BRANCH_NAME" | ||
|
|
||
| # Write Docker versions to file | ||
| echo "- $(docker --version)" > docker-versions.txt | ||
| echo "- $(docker compose version)" >> docker-versions.txt | ||
|
|
||
| # Only add the specific file we want | ||
| git add docker-versions.txt | ||
| if git diff-index --quiet HEAD --; then | ||
| echo "No changes to commit" | ||
|
|
||
| # Check if there are actually changes to commit | ||
| if git diff --cached --quiet; then | ||
| echo "No changes to docker-versions.txt, skipping PR creation" | ||
| else | ||
| git commit -m "Update Docker versions" | ||
| git push origin docker-versions-update | ||
| echo 'y' | gh pr create --fill | ||
| # Check if an open PR already exists | ||
| EXISTING_PR=$(gh pr list --base main --state open --search "chore: update Docker versions in:title" --json number --jq '.[0].number // empty') | ||
| if [ -n "$EXISTING_PR" ]; then | ||
| echo "Open PR #$EXISTING_PR already exists for Docker version updates, skipping PR creation" | ||
| echo "You can view it at: $(gh pr view $EXISTING_PR --json url --jq '.url')" | ||
| else | ||
| git commit -m "chore: update Docker versions" | ||
| git push origin "$BRANCH_NAME" | ||
| # Create PR with explicit title and body instead of --fill | ||
| gh pr create \ | ||
| --title "chore: update Docker versions" \ | ||
| --body "Automated update of docker-versions.txt with current Docker and Docker Compose versions. | ||
|
|
||
| **Changes:** | ||
| - Updated Docker version information | ||
| - Updated Docker Compose version information | ||
|
|
||
| This PR only contains changes to docker-versions.txt and no other files." \ | ||
| --base main \ | ||
| --head "$BRANCH_NAME" | ||
| fi | ||
| fi | ||
|
|
||
| - name: Check for Dockerfile and context changes | ||
| # This step checks for changes in Dockerfile and context | ||
| run: | | ||
| HAS_DOCKER_CHANGES=false | ||
| for file in ${{ env.files }}; do | ||
| if [[ $file =~ (^|/)Dockerfile($|/)|(^|/)dockerfiles/ ]]; then | ||
| echo "Dockerfile or dockerfiles directory has changed." | ||
| echo "Changed file: $file" | ||
| if [[ "$file" =~ (^|/)Dockerfile($|/)|(^|/)dockerfiles/ ]]; then | ||
| echo "Dockerfile or dockerfiles directory has changed: $file" | ||
| HAS_DOCKER_CHANGES=true | ||
| break | ||
| fi | ||
| done | ||
|
|
||
| if (( $? == 0 )); then | ||
|
|
||
| echo "HAS_DOCKER_CHANGES=$HAS_DOCKER_CHANGES" >> $GITHUB_ENV | ||
|
|
||
| if [[ "$HAS_DOCKER_CHANGES" == "false" ]]; then | ||
| echo "No Dockerfile or context directory changes. Skipping Docker image build and push steps." | ||
| echo "Changed files: ${{ env.files }}" | ||
| fi | ||
|
|
@@ -87,7 +118,7 @@ jobs: | |
| - | ||
| name: Login to GitHub Container Registry | ||
| # This step logs in to GHCR | ||
| if: contains(env.files, 'Dockerfile') | ||
| if: env.HAS_DOCKER_CHANGES == 'true' && env.IS_FORK != 'true' | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
|
|
@@ -103,91 +134,83 @@ jobs: | |
| echo "BRANCH=$BRANCH_NAME" >> $GITHUB_ENV | ||
| id: extract_branch | ||
|
|
||
| - name: Extract branch name and set BRANCH environment variable | ||
| # This step extracts the branch name and sets the BRANCH environment variable | ||
| shell: bash | ||
| run: | | ||
| BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed -e 's#/#-#g') | ||
| if [[ "$BRANCH_NAME" == "main" ]]; then BRANCH_NAME=""; fi | ||
| echo "BRANCH=$BRANCH_NAME" >> $GITHUB_ENV | ||
|
|
||
| - name: Set repository name to lowercase | ||
| # This step sets the repository name to lowercase | ||
| run: echo "REPO_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | ||
|
|
||
| - name: Build and push a simple jenkins controller | ||
| # This step builds and pushes a simple Jenkins controller | ||
| if: contains(env.files, 'dockerfiles/Dockerfile') || contains(env.files, 'dockerfiles/') | ||
| if: (contains(env.files, 'dockerfiles/Dockerfile') || contains(env.files, 'dockerfiles/')) && env.IS_FORK != 'true' | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: ./dockerfiles | ||
| platforms: linux/amd64, linux/aarch64 | ||
| platforms: linux/amd64, linux/arm64 | ||
| push: true | ||
| tags: ghcr.io/${{ env.REPO_NAME }}/jenkinsci-tutorials:simple_controller_${{ env.BRANCH }} | ||
|
|
||
| - name: Build and push the jenkins agent for maven tutorial | ||
| # This step builds and pushes the Jenkins agent for the Maven tutorial | ||
| if: contains(env.files, 'dockerfiles/maven/Dockerfile') | ||
| if: contains(env.files, 'dockerfiles/maven/') && env.IS_FORK != 'true' | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: ./dockerfiles/maven | ||
| platforms: linux/amd64, linux/aarch64 | ||
| platforms: linux/amd64, linux/arm64 | ||
| push: true | ||
| tags: ghcr.io/${{ env.REPO_NAME }}/jenkinsci-tutorials:maven_agent_${{ env.BRANCH }} | ||
|
|
||
| - name: Build and push the jenkins agent for python tutorial | ||
| # This step builds and pushes the Jenkins agent for the Python tutorial | ||
| if: contains(env.files, 'dockerfiles/python/Dockerfile') | ||
| if: contains(env.files, 'dockerfiles/python/') && env.IS_FORK != 'true' | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: ./dockerfiles/python | ||
| platforms: linux/amd64, linux/aarch64 | ||
| platforms: linux/amd64, linux/arm64 | ||
| push: true | ||
| tags: ghcr.io/${{ env.REPO_NAME }}/jenkinsci-tutorials:python_agent_${{ env.BRANCH }} | ||
|
|
||
| - name: Build and push the jenkins agent for node tutorial | ||
| # This step builds and pushes the Jenkins agent for the Node.js tutorial | ||
| if: contains(env.files, 'dockerfiles/node/Dockerfile') | ||
| if: contains(env.files, 'dockerfiles/node/') && env.IS_FORK != 'true' | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: ./dockerfiles/node | ||
| platforms: linux/amd64, linux/aarch64 | ||
| platforms: linux/amd64, linux/arm64 | ||
| push: true | ||
| tags: ghcr.io/${{ env.REPO_NAME }}/jenkinsci-tutorials:node_agent_${{ env.BRANCH }} | ||
|
|
||
| - name: Build and push the jenkins agent for the sidekick container | ||
| # This step builds and pushes the Jenkins agent for the sidekick container | ||
| if: contains(env.files, 'dockerfiles/sidekick/Dockerfile') | ||
| if: contains(env.files, 'dockerfiles/sidekick/') && env.IS_FORK != 'true' | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: ./dockerfiles/sidekick | ||
| platforms: linux/amd64, linux/aarch64 | ||
| platforms: linux/amd64, linux/arm64 | ||
| push: true | ||
| tags: ghcr.io/${{ env.REPO_NAME }}/jenkinsci-tutorials:sidekick_${{ env.BRANCH }} | ||
|
|
||
| - name: Build and push the jenkins agent for the agent-finding container | ||
| # This step builds and pushes the Jenkins agent for the agent-finding container | ||
| if: contains(env.files, 'dockerfiles/agent-discovery/Dockerfile') | ||
| if: contains(env.files, 'dockerfiles/agent-discovery/') && env.IS_FORK != 'true' | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: ./dockerfiles/agent-discovery/ | ||
| platforms: linux/amd64, linux/aarch64 | ||
| platforms: linux/amd64, linux/arm64 | ||
| push: true | ||
| tags: ghcr.io/${{ env.REPO_NAME }}/jenkinsci-tutorials:agent_discovery_${{ env.BRANCH }} | ||
|
|
||
| - name: Build and push the jenkins agent for multi-branch controller | ||
| # This step builds and pushes the Jenkins agent for the multi-branch controller | ||
| if: contains(env.files, 'dockerfiles/multi/Dockerfile') | ||
| if: contains(env.files, 'dockerfiles/multi/') && env.IS_FORK != 'true' | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: ./dockerfiles/multi | ||
| platforms: linux/amd64, linux/aarch64 | ||
| platforms: linux/amd64, linux/arm64 | ||
| push: true | ||
| tags: ghcr.io/${{ env.REPO_NAME }}/jenkinsci-tutorials:multi_controller_${{ env.BRANCH }} | ||
|
|
||
| - name: Build and push the jenkins agent for Android | ||
| # This step builds and pushes the Jenkins agent for Android | ||
| if: contains(env.files, 'dockerfiles/android/Dockerfile') | ||
| if: contains(env.files, 'dockerfiles/android/') && env.IS_FORK != 'true' | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: ./dockerfiles/android | ||
|
|
@@ -197,7 +220,7 @@ jobs: | |
|
|
||
| - name: Build and push the jenkins agent for golang tutorial | ||
| # This step builds and pushes the Jenkins agent for the Golang tutorial | ||
| if: contains(env.files, 'dockerfiles/golang/Dockerfile') | ||
| if: contains(env.files, 'dockerfiles/golang/') && env.IS_FORK != 'true' | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: ./dockerfiles/golang | ||
|
|
@@ -207,20 +230,20 @@ jobs: | |
|
|
||
| - name: Build and push the jenkins agent for cpp tutorial | ||
| # This step builds and pushes the Jenkins agent for the C++ tutorial | ||
| if: contains(env.files, 'dockerfiles/cpp/Dockerfile') | ||
| if: contains(env.files, 'dockerfiles/cpp/') && env.IS_FORK != 'true' | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: ./dockerfiles/cpp | ||
| platforms: linux/amd64, linux/aarch64 | ||
| platforms: linux/amd64, linux/arm64 | ||
| push: true | ||
| tags: ghcr.io/${{ env.REPO_NAME }}/jenkinsci-tutorials:cpp_${{ env.BRANCH }} | ||
|
|
||
| - name: Build and push the jenkins agent for dotnet tutorial | ||
| # This step builds and pushes the Jenkins agent for the C++ tutorial | ||
| if: contains(env.files, 'dockerfiles/dotnet/Dockerfile') | ||
| # This step builds and pushes the Jenkins agent for the .NET tutorial | ||
| if: contains(env.files, 'dockerfiles/dotnet/') && env.IS_FORK != 'true' | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: ./dockerfiles/dotnet | ||
| platforms: linux/amd64, linux/aarch64 | ||
| platforms: linux/amd64, linux/arm64 | ||
| push: true | ||
| tags: ghcr.io/${{ env.REPO_NAME }}/jenkinsci-tutorials:dotnet_${{ env.BRANCH }} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical YAML syntax error: fix multi-line PR body.
Static analysis confirms line 81 causes a YAML parsing error because
**Changes:**at the line start is interpreted as YAML syntax. The backslash-continued multi-line string is fragile.Use a heredoc to avoid YAML parsing issues:
🧰 Tools
🪛 actionlint (1.7.7)
81-81: could not parse as YAML: yaml: line 81: did not find expected alphabetic or numeric character
(syntax-check)
🪛 YAMLlint (1.37.1)
[error] 81-81: syntax error: expected alphabetic or numeric character, but found '*'
(syntax)