docker image building and pushing #1942
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: docker image building and pushing | |
on: | |
push: | |
branches: | |
- '*' | |
pull_request: | |
branches: [ '*' ] | |
schedule: | |
# * is a special character in YAML so you have to quote this string | |
# Will build everyday at 4:30 and 16:30 | |
- cron: '30 4,16 * * *' | |
env: | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- | |
name: Retrieve modified files | |
id: changes | |
run: echo "::set-output name=files::$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})" | |
- | |
name: Check for Dockerfile and context changes | |
run: | | |
if [[ $(echo "${{ steps.changes.outputs.files }}" | grep -E "(^|/)Dockerfile($|/)|(^|/)context/") ]]; then | |
echo "Dockerfile or context directory has changed." | |
echo Changed files are | |
echo "${{ steps.changes.outputs.files }}" | |
else | |
echo "No Dockerfile or context directory changes. Skipping Docker image build and push steps." | |
echo changed files are | |
echo "${{ steps.changes.outputs.files }}" | |
exit 0 | |
fi | |
- | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- | |
name: Login to DockerHub | |
if: contains(steps.changes.outputs.files, 'Dockerfile') | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Extract branch name | |
if: contains(steps.changes.outputs.files, 'Dockerfile') | |
shell: bash | |
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/} | sed -e 's#/#-#g')" | |
id: extract_branch | |
- name: Extract branch name and set 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: Build and push a simple bundled instance | |
if: contains(steps.changes.outputs.files, '00_old_one_from_proposal/Dockerfile') | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./00_old_one_from_proposal | |
platforms: linux/amd64, linux/aarch64 | |
push: true | |
tags: ${{ env.DOCKERHUB_USERNAME }}/jenkinsci-tutorials:00_old_one_${{ env.BRANCH }} | |
- | |
name: Build and push a simple jenkins controller | |
if: contains(steps.changes.outputs.files, 'dockerfiles/Dockerfile') | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./dockerfiles | |
platforms: linux/amd64, linux/aarch64 | |
push: true | |
tags: ${{ env.DOCKERHUB_USERNAME }}/jenkinsci-tutorials:simple_controller_${{ env.BRANCH }} | |
- | |
name: Build and push the jenkins agent for maven tutorial | |
if: contains(steps.changes.outputs.files, 'dockerfiles/maven/Dockerfile') | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./dockerfiles/maven | |
platforms: linux/amd64, linux/aarch64 | |
push: true | |
tags: ${{ env.DOCKERHUB_USERNAME }}/jenkinsci-tutorials:maven_agent_${{ env.BRANCH }} | |
- | |
name: Build and push the jenkins agent for python tutorial | |
if: contains(steps.changes.outputs.files, 'dockerfiles/python/Dockerfile') | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./dockerfiles/python | |
platforms: linux/amd64, linux/aarch64 | |
push: true | |
tags: ${{ env.DOCKERHUB_USERNAME }}/jenkinsci-tutorials:python_agent_${{ env.BRANCH }} | |
- | |
name: Build and push the jenkins agent for node tutorial | |
if: contains(steps.changes.outputs.files, 'dockerfiles/node/Dockerfile') | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./dockerfiles/node | |
platforms: linux/amd64, linux/aarch64 | |
push: true | |
tags: ${{ env.DOCKERHUB_USERNAME }}/jenkinsci-tutorials:node_agent_${{ env.BRANCH }} | |
- | |
name: Build and push the jenkins agent for sidekick tutorial | |
if: contains(steps.changes.outputs.files, 'dockerfiles/sidekick/Dockerfile') | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./dockerfiles/sidekick | |
platforms: linux/amd64, linux/aarch64 | |
push: true | |
tags: ${{ env.DOCKERHUB_USERNAME }}/jenkinsci-tutorials:sidekick_${{ env.BRANCH }} | |
- | |
name: Build and push the jenkins agent for multi-branch controller | |
if: contains(steps.changes.outputs.files, '06_multibranch_pipeline/dockerfiles') | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./06_multibranch_pipeline/dockerfiles/ | |
platforms: linux/amd64, linux/aarch64 | |
push: true | |
tags: ${{ env.DOCKERHUB_USERNAME }}/jenkinsci-tutorials:multi_controller_${{ env.BRANCH }} |