|
| 1 | +name: OpenEMR Docker Build (current/next/dev) |
| 2 | + |
| 3 | +# One workflow for all three rotating slots. The matrix is the STABLE slot |
| 4 | +# names — never rotated. The actual OpenEMR version for each slot is carried by |
| 5 | +# the slot-named symlinks docker/openemr/{current,next,dev} -> the real version |
| 6 | +# dirs (e.g. 8.0.0). Rotation flips the symlinks (tools/release/SlotRotator), |
| 7 | +# so this file holds no version strings and never needs rewriting. |
| 8 | + |
| 9 | +on: |
| 10 | + workflow_dispatch: |
| 11 | + schedule: |
| 12 | + - cron: '0 2 * * *' # run at 2 AM UTC |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + if: github.repository_owner == 'openemr' && github.repository == 'openemr/openemr-devops' && github.ref == 'refs/heads/master' |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + slot: [current, next, dev] |
| 21 | + platform: |
| 22 | + - arch: linux/amd64 |
| 23 | + runner: ubuntu-24.04 |
| 24 | + - arch: linux/arm64 |
| 25 | + runner: ubuntu-24.04-arm |
| 26 | + runs-on: ${{ matrix.platform.runner }} |
| 27 | + steps: |
| 28 | + - name: Checkout |
| 29 | + uses: actions/checkout@v6 |
| 30 | + |
| 31 | + - name: Resolve slot version |
| 32 | + id: resolve |
| 33 | + run: | |
| 34 | + dir="$(basename "$(readlink "docker/openemr/${{ matrix.slot }}")")" |
| 35 | + echo "dir=$dir" >> "$GITHUB_OUTPUT" |
| 36 | +
|
| 37 | + - name: Prepare platform pair |
| 38 | + run: | |
| 39 | + platform=${{ matrix.platform.arch }} |
| 40 | + echo "PLATFORM_PAIR=${platform//\//-}" >> "$GITHUB_ENV" |
| 41 | +
|
| 42 | + - name: Set up Docker Buildx |
| 43 | + uses: docker/setup-buildx-action@v4 |
| 44 | + |
| 45 | + - name: Login to Docker Hub |
| 46 | + uses: docker/login-action@v4 |
| 47 | + with: |
| 48 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 49 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 50 | + |
| 51 | + - name: Build and push by digest |
| 52 | + id: build |
| 53 | + uses: docker/build-push-action@v7 |
| 54 | + with: |
| 55 | + context: docker/openemr/${{ steps.resolve.outputs.dir }} |
| 56 | + platforms: ${{ matrix.platform.arch }} |
| 57 | + outputs: type=image,name=openemr/openemr,push-by-digest=true,name-canonical=true,push=true |
| 58 | + no-cache: true |
| 59 | + |
| 60 | + - name: Export digest |
| 61 | + run: | |
| 62 | + mkdir -p /tmp/digests |
| 63 | + digest="${{ steps.build.outputs.digest }}" |
| 64 | + touch "/tmp/digests/${digest#sha256:}" |
| 65 | +
|
| 66 | + - name: Upload digest |
| 67 | + uses: actions/upload-artifact@v7 |
| 68 | + with: |
| 69 | + name: digests-${{ matrix.slot }}-${{ env.PLATFORM_PAIR }} |
| 70 | + path: /tmp/digests/* |
| 71 | + if-no-files-found: error |
| 72 | + retention-days: 1 |
| 73 | + |
| 74 | + merge: |
| 75 | + if: github.repository_owner == 'openemr' && github.repository == 'openemr/openemr-devops' && github.ref == 'refs/heads/master' |
| 76 | + runs-on: ubuntu-24.04 |
| 77 | + needs: build |
| 78 | + strategy: |
| 79 | + fail-fast: false |
| 80 | + matrix: |
| 81 | + include: |
| 82 | + - slot: current |
| 83 | + float: latest |
| 84 | + bare_dir: true |
| 85 | + - slot: next |
| 86 | + float: next |
| 87 | + bare_dir: true |
| 88 | + - slot: dev |
| 89 | + float: dev |
| 90 | + bare_dir: false |
| 91 | + steps: |
| 92 | + - name: Checkout |
| 93 | + uses: actions/checkout@v6 |
| 94 | + |
| 95 | + - name: Resolve slot version |
| 96 | + id: resolve |
| 97 | + run: | |
| 98 | + dir="$(basename "$(readlink "docker/openemr/${{ matrix.slot }}")")" |
| 99 | + ref="$(grep -oE '^ARG OPENEMR_VERSION=[A-Za-z0-9._-]+' "docker/openemr/${dir}/Dockerfile" | head -1 | cut -d= -f2)" |
| 100 | + curl -fsSL "https://raw.githubusercontent.com/openemr/openemr/${ref}/version.php" -o /tmp/version.php |
| 101 | + # shellcheck disable=SC2016 # PHP variables, not shell |
| 102 | + ver="$(php -r 'require "/tmp/version.php"; $rp = $v_realpatch > 0 ? "." . $v_realpatch : ""; echo $v_major . "." . $v_minor . "." . $v_patch . $rp . $v_tag;')" |
| 103 | + echo "dir=$dir" >> "$GITHUB_OUTPUT" |
| 104 | + echo "ver=$ver" >> "$GITHUB_OUTPUT" |
| 105 | +
|
| 106 | + - name: Download digests |
| 107 | + uses: actions/download-artifact@v8 |
| 108 | + with: |
| 109 | + path: /tmp/digests |
| 110 | + pattern: digests-${{ matrix.slot }}-* |
| 111 | + merge-multiple: true |
| 112 | + |
| 113 | + - name: Set up Docker Buildx |
| 114 | + uses: docker/setup-buildx-action@v4 |
| 115 | + |
| 116 | + - name: Login to Docker Hub |
| 117 | + uses: docker/login-action@v4 |
| 118 | + with: |
| 119 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 120 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 121 | + |
| 122 | + - name: Get build date |
| 123 | + id: build_date |
| 124 | + run: echo "date=$(date +'%Y-%m-%d')" >> "$GITHUB_OUTPUT" |
| 125 | + |
| 126 | + - name: Create manifest and push |
| 127 | + working-directory: /tmp/digests |
| 128 | + env: |
| 129 | + VER: ${{ steps.resolve.outputs.ver }} |
| 130 | + DIR: ${{ steps.resolve.outputs.dir }} |
| 131 | + FLOAT: ${{ matrix.float }} |
| 132 | + BUILD_DATE: ${{ steps.build_date.outputs.date }} |
| 133 | + BARE_DIR: ${{ matrix.bare_dir }} |
| 134 | + run: | |
| 135 | + mapfile -t digests < <(find . -maxdepth 1 -type f -printf 'openemr/openemr@sha256:%f\n') |
| 136 | + tags=(-t "openemr/openemr:${VER}" -t "openemr/openemr:${FLOAT}" -t "openemr/openemr:${VER}-${BUILD_DATE}") |
| 137 | + if [ "${BARE_DIR}" = "true" ] && [ "${DIR}" != "${VER}" ]; then |
| 138 | + tags+=(-t "openemr/openemr:${DIR}") |
| 139 | + fi |
| 140 | + docker buildx imagetools create "${tags[@]}" "${digests[@]}" |
| 141 | +
|
| 142 | + - name: Push Docker Hub readme |
| 143 | + uses: ./.github/actions/push-dockerhub-readme |
| 144 | + with: |
| 145 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 146 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
0 commit comments