11name : Build and Push Docker Image
22
3- # Trigger workflow on tag pushes (e.g., v1.0.0, release-1.2.3)
43on :
54 push :
65 # tags:
76 # - '*'
87
98jobs :
10- # First job: Build all Maven modules and prepare dependencies
11- # This job builds the root POM and all sub-modules, then uploads the Maven repository
12- # as an artifact so the Docker build job can use the same dependencies
139 root-pom-build :
1410 runs-on : ubuntu-latest
1511 outputs :
16- # Output the Maven cache key for potential use by other jobs
1712 maven-cache-key : ${{ steps.cache-maven.outputs.cache-primary-key }}
18- env :
19- # Environment variables for schema and blob paths (same as pr-actions.yml)
20- # These may be used by the application during build/test
21- SCHEMA_BASE_PATH : ${{ vars.SCHEMA_BASE_PATH }}
22- BLOB_IMAGE_CONTENT_PATH : ${{ vars.BLOB_IMAGE_CONTENT_PATH }}
23- BLOB_VIDEO_CONTENT_PATH : ${{ vars.BLOB_VIDEO_CONTENT_PATH }}
2413 steps :
25- # Step 1: Checkout the source code
2614 - name : Checkout code
2715 uses : actions/checkout@v3
2816
29- # Step 2: Set up Java 11 environment first (before caching, like pr-actions.yml)
30- # Uses Temurin distribution for better performance and reliability
31- - name : Set up JDK 11
32- uses : actions/setup-java@v3
33- with :
34- java-version : ' 11'
35- distribution : ' temurin'
36- cache : ' maven' # Additional Maven caching provided by setup-java
37-
38- # Step 3: Cache Maven dependencies to speed up builds
39- # This caches the ~/.m2/repository directory between workflow runs
40- # The cache key is based on the hash of all pom.xml files
4117 - name : Cache Maven packages
4218 id : cache-maven
4319 uses : actions/cache@v3
@@ -47,61 +23,46 @@ jobs:
4723 restore-keys : |
4824 ${{ runner.os }}-maven-
4925
50- # Step 4: Build all Maven modules (optimized approach)
51- # This step builds the entire project in the correct dependency order
52- # Using the same pattern as pr-actions.yml for consistency
26+ - name : Set up JDK 11
27+ uses : actions/setup-java@v3
28+ with :
29+ java-version : ' 11'
30+ distribution : ' temurin'
31+ cache : ' maven'
32+
33+ - name : Set up Maven 3.8.7
34+ uses : s4u/setup-maven-action@v1.11.0
35+ with :
36+ maven-version : 3.8.7
37+
5338 - name : Build root POM and all modules
5439 run : |
55- # First, build only the root POM (parent project) without building modules
56- # -N flag means "non-recursive" - only build the current project
40+ # Build root POM first
5741 mvn clean install -N -DskipTests
5842
59- # Then build all modules recursively with optimized flags
60- # This will build: jobs-core, notification, lms-jobs, user-org-jobs, ml-jobs
61- # All dependencies will be resolved and installed to local Maven repository
43+ # Build all modules (jobs-core, notification, lms-jobs, user-org-jobs, ml-jobs)
6244 mvn clean install -DskipTests
6345
64- # Step 5: Upload Maven repository as artifact
65- # This makes the built dependencies available to the Docker build job
66- # The Docker job needs these dependencies to build jobs-distribution
6746 - name : Upload Maven local repository
6847 uses : actions/upload-artifact@v4.6.2
6948 with :
7049 name : maven-repo
7150 path : ~/.m2/repository
72- retention-days : 1 # Keep for 1 day to allow for debugging
51+ retention-days : 1
7352
74- # Second job: Build Docker image and push to registry
75- # This job depends on the first job and uses the Maven dependencies
76- # that were built and uploaded as artifacts
77- # Optimized with pr-actions.yml patterns
7853 build-and-push-docker :
79- # Wait for the root-pom-build job to complete successfully
8054 needs : root-pom-build
8155 runs-on : ubuntu-latest
8256 steps :
83- # Step 1: Checkout the source code (needed for Docker build context)
8457 - name : Checkout code
8558 uses : actions/checkout@v3
8659
87- # Step 2: Set up Java 11 environment first (consistent with pr-actions.yml pattern)
88- - name : Set up JDK 11
89- uses : actions/setup-java@v3
90- with :
91- java-version : ' 11'
92- distribution : ' temurin'
93- cache : ' maven'
94-
95- # Step 3: Download the Maven repository from the previous job
96- # This contains all the built dependencies needed for jobs-distribution
9760 - name : Restore Maven local repository
9861 uses : actions/download-artifact@v4.3.0
9962 with :
10063 name : maven-repo
10164 path : ~/.m2/repository
10265
103- # Step 4: Cache Maven packages (same as first job)
104- # This ensures we have the same caching benefits in this job
10566 - name : Cache Maven packages
10667 uses : actions/cache@v3
10768 with :
@@ -110,58 +71,53 @@ jobs:
11071 restore-keys : |
11172 ${{ runner.os }}-maven-
11273
113- # Step 5: Authenticate with Docker registry
114- # Supports multiple registry providers: GCP, Azure, Docker Hub, or GitHub Container Registry
74+ - name : Set up JDK 11
75+ uses : actions/setup-java@v3
76+ with :
77+ java-version : ' 11'
78+ distribution : ' temurin'
79+ cache : ' maven'
80+
81+ - name : Set up Maven 3.8.7
82+ uses : s4u/setup-maven-action@v1.11.0
83+ with :
84+ maven-version : 3.8.7
85+
11586 - name : Login Docker Registry
11687 run : |
11788 case "${{ vars.REGISTRY_PROVIDER }}" in
11889 "gcp")
119- # Google Cloud Platform Container Registry
12090 echo "${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}" | base64 --decode > $HOME/gcloud-key.json
12191 gcloud auth activate-service-account --key-file=$HOME/gcloud-key.json
12292 gcloud auth configure-docker ${{ secrets.REGISTRY_NAME }}
12393 REGISTRY_URL=$(echo "${{ secrets.REGISTRY_URL }}" | tr '[:upper:]' '[:lower:]')
12494 ;;
12595 "azure" | "dockerhub")
126- # Azure Container Registry or Docker Hub
12796 echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login "${{ secrets.REGISTRY_NAME }}" \
12897 --username "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
12998 REGISTRY_URL="$(echo "${{ secrets.REGISTRY_URL }}/$(basename "${{ github.workspace }}")" | tr '[:upper:]' '[:lower:]')"
13099 ;;
131100 *)
132- # Default: GitHub Container Registry (ghcr.io)
133101 REPO_NAME_LOWERCASE=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')
134102 echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
135103 REGISTRY_URL="ghcr.io/$REPO_NAME_LOWERCASE"
136104 ;;
137105 esac
138106 echo "REGISTRY_URL=${REGISTRY_URL}" >> $GITHUB_ENV
139107
140- # Step 6: Build the jobs-distribution module
141- # This module creates the final distribution package that gets included in the Docker image
142- # It depends on all the modules built in the previous job
143108 - name : Build jobs-distribution
144109 working-directory : jobs-distribution
145110 run : |
146- # Package the distribution (creates jobs-distribution-1.0.tar.gz)
147- # This contains all the job JARs and dependencies
148111 mvn package -DskipTests
149112
150- # Step 7: Build and push Docker image (combined step for efficiency)
151- # Uses the Dockerfile in jobs-distribution directory
152- # The image contains the Flink runtime and our job distribution
153- - name : Build and Push Docker Image
113+ - name : Build Docker Image
154114 working-directory : jobs-distribution
155115 run : |
156- # Create image tag from git ref and commit SHA
157- # Format: <tag-name>_<first-7-chars-of-sha>
158- # Example: v1.0.0_a1b2c3d
159116 IMAGE_TAG=$(echo "${{ github.ref_name }}_$(echo $GITHUB_SHA | cut -c1-7)" | tr '[:upper:]' '[:lower:]')
160-
161- # Build the Docker image
162- # The Dockerfile copies jobs-distribution-1.0.tar.gz and extracts it
163117 docker build -t ${REGISTRY_URL}:${IMAGE_TAG} .
164-
165- # Push the tagged image to the configured registry immediately after build
118+ echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
119+
120+ - name : Push Docker Image
121+ run : |
166122 docker push ${REGISTRY_URL}:${IMAGE_TAG}
167- echo "Successfully built and pushed Docker image: ${REGISTRY_URL}:${IMAGE_TAG}"
123+ echo "Pushed Docker image: ${REGISTRY_URL}:${IMAGE_TAG}"
0 commit comments