Build Solution Images (BE + FE) #53
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
| name: Build Solution Images (BE + FE) | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Main tag prefix (e.g. v1.5, latest, dev)' | |
| required: true | |
| default: 'latest' | |
| solution: | |
| description: 'Solution name (e.g. coreMIS)' | |
| required: true | |
| scope: | |
| description: 'What to build (be / fe / all). Use with act to avoid re-running the other side on failure.' | |
| required: true | |
| default: 'all' | |
| type: choice | |
| options: | |
| - be | |
| - fe | |
| - all | |
| platform: | |
| description: 'Target platform' | |
| required: false | |
| default: 'all' | |
| type: choice | |
| options: | |
| - amd64 | |
| - arm64 | |
| - all | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| steps: | |
| # ------------------------------------------------- | |
| # 1. Checkout all repos + discover what to build | |
| # ------------------------------------------------- | |
| - name: Checkout solutions repo | |
| uses: actions/checkout@v4 | |
| # No 'path:' → solution folders (coreMIS/, etc.) are directly in workspace root | |
| # This avoids nesting issues with act and makes paths consistent locally + on GitHub | |
| - name: Set BE repo and ref | |
| run: | | |
| JSON_FILE="${{ inputs.solution }}/consolidated-solution.json" | |
| if [ -f "$JSON_FILE" ]; then | |
| BE_GIT_URL=$(jq -r '.bePackages.definitions.assembly.git // empty' "$JSON_FILE") | |
| BE_REF=$(jq -r '.bePackages.definitions.assembly.branch // "develop"' "$JSON_FILE") | |
| if [ -n "$BE_GIT_URL" ]; then | |
| BE_REPO=$(echo "$BE_GIT_URL" | sed -E 's|https://github.com/([^/]+)/([^/]+)(\.git)?$|\1/\2|') | |
| else | |
| BE_REPO="openimis/openimis-be_py" | |
| BE_REF="develop" | |
| fi | |
| else | |
| BE_REPO="openimis/openimis-be_py" | |
| BE_REF="develop" | |
| fi | |
| echo "BE_REPO=$BE_REPO" >> $GITHUB_ENV | |
| echo "BE_REF=$BE_REF" >> $GITHUB_ENV | |
| - name: Set FE repo and ref | |
| run: | | |
| JSON_FILE="${{ inputs.solution }}/consolidated-solution.json" | |
| if [ -f "$JSON_FILE" ]; then | |
| FE_GIT_URL=$(jq -r '.fePackages.definitions.assembly.git // empty' "$JSON_FILE") | |
| FE_REF=$(jq -r '.fePackages.definitions.assembly.branch // "develop"' "$JSON_FILE") | |
| if [ -n "$FE_GIT_URL" ]; then | |
| FE_REPO=$(echo "$FE_GIT_URL" | sed -E 's|https://github.com/([^/]+)/([^/]+)(\.git)?$|\1/\2|') | |
| else | |
| FE_REPO="openimis/openimis-fe_js" | |
| FE_REF="develop" | |
| fi | |
| else | |
| FE_REPO="openimis/openimis-fe_js" | |
| FE_REF="develop" | |
| fi | |
| echo "FE_REPO=$FE_REPO" >> $GITHUB_ENV | |
| echo "FE_REF=$FE_REF" >> $GITHUB_ENV | |
| - name: Checkout openimis-be_py | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ env.BE_REPO }} | |
| ref: ${{ env.BE_REF }} | |
| path: openimis-be_py | |
| token: ${{ secrets.GITHUB_TOKEN || 'dummy-token-for-act' }} | |
| - name: Checkout openimis-fe_js | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ env.FE_REPO }} | |
| ref: ${{ env.FE_REF }} | |
| path: openimis-fe_js | |
| token: ${{ secrets.GITHUB_TOKEN || 'dummy-token-for-act' }} | |
| - name: Check solution components | |
| run: | | |
| SCOPE="${{ inputs.scope }}" | |
| BUILD_BE=false | |
| BUILD_FE=false | |
| if [ "$SCOPE" = "be" ] || [ "$SCOPE" = "all" ]; then | |
| [ -f "${{ inputs.solution }}/be-openimis.json" ] && BUILD_BE=true | |
| fi | |
| if [ "$SCOPE" = "fe" ] || [ "$SCOPE" = "all" ]; then | |
| [ -f "${{ inputs.solution }}/fe-openimis.json" ] && BUILD_FE=true | |
| fi | |
| echo "BUILD_BE=$BUILD_BE" >> $GITHUB_ENV | |
| echo "BUILD_FE=$BUILD_FE" >> $GITHUB_ENV | |
| echo "=== Solution: ${{ inputs.solution }} (scope=$SCOPE) ===" | |
| echo "build_be=$BUILD_BE" | |
| echo "build_fe=$BUILD_FE" | |
| # ------------------------------------------------- | |
| # 2. Docker setup + login (once) | |
| # ------------------------------------------------- | |
| - uses: docker/setup-qemu-action@v3 | |
| - uses: docker/setup-buildx-action@v3 | |
| - uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # ------------------------------------------------- | |
| # 3. Build solution images (no more shared base) | |
| # ------------------------------------------------- | |
| - name: Prepare BE build context | |
| if: env.BUILD_BE == 'true' | |
| run: | | |
| LOWER_SOL=$(echo "${{ inputs.solution }}" | tr '[:upper:]' '[:lower:]') | |
| BUILD_DIR="build-be-$LOWER_SOL" | |
| mkdir -p "$BUILD_DIR" | |
| cp -r openimis-be_py/* "$BUILD_DIR/" | |
| if [ ! -f "${{ inputs.solution }}/be-openimis.json" ]; then | |
| echo "ERROR: be-openimis.json not found in ${{ inputs.solution }}" | |
| exit 1 | |
| fi | |
| cp "${{ inputs.solution }}/be-openimis.json" "$BUILD_DIR/openimis.json" | |
| echo "=== BE openimis.json for ${{ inputs.solution }} ===" | |
| cat "$BUILD_DIR/openimis.json" | |
| echo "=== END ===" | |
| [ -d "${{ inputs.solution }}/fixtures" ] && cp -r "${{ inputs.solution }}/fixtures" "$BUILD_DIR/" || echo "No fixtures" | |
| echo "BUILD_DIR_BE=$BUILD_DIR" >> $GITHUB_ENV | |
| echo "LOWER_SOL=$LOWER_SOL" >> $GITHUB_ENV | |
| echo "TAG_BE=${{ inputs.tag }}-$LOWER_SOL" >> $GITHUB_ENV | |
| - name: Prepare FE build context | |
| if: env.BUILD_FE == 'true' | |
| run: | | |
| LOWER_SOL=$(echo "${{ inputs.solution }}" | tr '[:upper:]' '[:lower:]') | |
| BUILD_DIR="build-fe-$LOWER_SOL" | |
| mkdir -p "$BUILD_DIR" | |
| cp -r openimis-fe_js/* "$BUILD_DIR/" | |
| if [ ! -f "${{ inputs.solution }}/fe-openimis.json" ]; then | |
| echo "ERROR: fe-openimis.json not found in ${{ inputs.solution }}" | |
| exit 1 | |
| fi | |
| cp "${{ inputs.solution }}/fe-openimis.json" "$BUILD_DIR/openimis.json" | |
| echo "=== FE openimis.json for ${{ inputs.solution }} ===" | |
| cat "$BUILD_DIR/openimis.json" | |
| echo "=== END ===" | |
| echo "BUILD_DIR_FE=$BUILD_DIR" >> $GITHUB_ENV | |
| echo "LOWER_SOL=$LOWER_SOL" >> $GITHUB_ENV | |
| echo "TAG_FE=${{ inputs.tag }}-$LOWER_SOL" >> $GITHUB_ENV | |
| - name: Debug - List build context (BE) | |
| if: env.BUILD_BE == 'true' | |
| run: | | |
| echo "=== Contents of ${{ env.BUILD_DIR_BE }} ===" | |
| ls -la ${{ env.BUILD_DIR_BE }} | |
| echo "=== Contents of ${{ env.BUILD_DIR_BE }}/fixtures ===" | |
| ls -la ${{ env.BUILD_DIR_BE }}/fixtures || echo "fixtures/ not found!" | |
| - name: Build BE solution image | |
| if: env.BUILD_BE == 'true' | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ${{ env.BUILD_DIR_BE }} | |
| file: ${{ env.BUILD_DIR_BE }}/Dockerfile | |
| platforms: ${{ inputs.platform == 'all' && 'linux/amd64,linux/arm64' || format('linux/{0}', inputs.platform) }} | |
| push: true | |
| tags: | | |
| ghcr.io/openimis/openimis-be:${{ env.TAG_BE }} | |
| cache-from: type=gha,scope=solution-${{ env.LOWER_SOL }}-be | |
| cache-to: type=gha,mode=max,scope=solution-${{ env.LOWER_SOL }}-be | |
| - name: Build FE solution image | |
| if: env.BUILD_FE == 'true' | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ${{ env.BUILD_DIR_FE }} | |
| file: ${{ env.BUILD_DIR_FE }}/Dockerfile | |
| platforms: ${{ inputs.platform == 'all' && 'linux/amd64,linux/arm64' || format('linux/{0}', inputs.platform) }} | |
| push: true | |
| tags: | | |
| ghcr.io/openimis/openimis-fe:${{ env.TAG_FE }} | |
| cache-from: type=gha,scope=solution-${{ env.LOWER_SOL }}-fe | |
| cache-to: type=gha,mode=max,scope=solution-${{ env.LOWER_SOL }}-fe | |
| build-args: | | |
| NPM_CONFIG_FETCH_TIMEOUT=600000 | |
| NPM_CONFIG_FETCH_RETRY_MINTIMEOUT=30000 | |
| NPM_CONFIG_FETCH_RETRY_MAXTIMEOUT=120000 |