|
| 1 | +on: |
| 2 | + push: |
| 3 | + branches: |
| 4 | + - main |
| 5 | + - develop |
| 6 | + tags: |
| 7 | + - '*' |
| 8 | + pull_request: |
| 9 | + paths: |
| 10 | + - '.github/workflows/build-onpremise.yml' |
| 11 | + - 'docker/prod/**' |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +permissions: |
| 15 | + packages: write |
| 16 | + contents: read |
| 17 | + attestations: write |
| 18 | + id-token: write |
| 19 | + |
| 20 | +env: |
| 21 | + DOCKER_REPO: registry.on-premise.solidtime.io/solidtime/solidtime |
| 22 | + |
| 23 | +name: Build - On Premise |
| 24 | +jobs: |
| 25 | + build: |
| 26 | + strategy: |
| 27 | + matrix: |
| 28 | + include: |
| 29 | + - runs-on: "ubuntu-24.04-arm" |
| 30 | + platform: "linux/arm64" |
| 31 | + - runs-on: "ubuntu-24.04" |
| 32 | + platform: "linux/amd64" |
| 33 | + runs-on: ${{ matrix.runs-on }} |
| 34 | + timeout-minutes: 90 |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: "Check out code" |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + fetch-depth: 0 # Required for WyriHaximus/github-action-get-previous-tag |
| 41 | + |
| 42 | + - name: "Get build" |
| 43 | + id: release-build |
| 44 | + run: echo "build=$(git rev-parse --short=8 HEAD)" >> "$GITHUB_OUTPUT" |
| 45 | + |
| 46 | + - name: "Get Previous tag (normal push)" |
| 47 | + id: previoustag |
| 48 | + if: ${{ !startsWith(github.ref, 'refs/tags/v') }} |
| 49 | + uses: "WyriHaximus/github-action-get-previous-tag@v1" |
| 50 | + with: |
| 51 | + prefix: "v" |
| 52 | + |
| 53 | + - name: "Get version" |
| 54 | + id: release-version |
| 55 | + run: | |
| 56 | + if ${{ !startsWith(github.ref, 'refs/tags/v') }}; then |
| 57 | + if ${{ startsWith(steps.previoustag.outputs.tag, 'v') }}; then |
| 58 | + version=$(echo "${{ steps.previoustag.outputs.tag }}" | cut -c 2-) |
| 59 | + echo "app_version=${version}" >> "$GITHUB_OUTPUT" |
| 60 | + else |
| 61 | + echo "ERROR: No previous tag found"; |
| 62 | + exit 1; |
| 63 | + fi |
| 64 | + else |
| 65 | + version=$(echo "${{ github.ref }}" | cut -c 12-) |
| 66 | + echo "app_version=${version}" >> "$GITHUB_OUTPUT" |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: "Copy .env template for production" |
| 70 | + run: | |
| 71 | + cp .env.production .env |
| 72 | + rm .env.production .env.ci .env.example |
| 73 | +
|
| 74 | + - name: "Add version to .env" |
| 75 | + run: sed -i 's/APP_VERSION=0.0.0/APP_VERSION=${{ steps.release-version.outputs.app_version }}/g' .env |
| 76 | + |
| 77 | + - name: "Add build to .env" |
| 78 | + run: sed -i 's/APP_BUILD=0/APP_BUILD=${{ steps.release-build.outputs.build }}/g' .env |
| 79 | + |
| 80 | + - name: "Output .env" |
| 81 | + run: cat .env |
| 82 | + |
| 83 | + - name: "Setup PHP with PECL extension" |
| 84 | + uses: shivammathur/setup-php@v2 |
| 85 | + with: |
| 86 | + php-version: '8.3' |
| 87 | + extensions: mbstring, dom, fileinfo, pgsql |
| 88 | + |
| 89 | + - name: "Install dependencies" |
| 90 | + run: composer install --no-dev --no-ansi --no-interaction --prefer-dist --ignore-platform-reqs --classmap-authoritative |
| 91 | + if: steps.cache-vendor.outputs.cache-hit != 'true' # Skip if cache hit |
| 92 | + |
| 93 | + - name: "Use Node.js" |
| 94 | + uses: actions/setup-node@v4 |
| 95 | + with: |
| 96 | + node-version: '20.x' |
| 97 | + |
| 98 | + - name: "Checkout invoicing extension" |
| 99 | + uses: actions/checkout@v4 |
| 100 | + with: |
| 101 | + repository: solidtime-io/extension-invoicing |
| 102 | + path: extensions/Invoicing |
| 103 | + ssh-key: ${{ secrets.SSH_PRIVATE_KEY_INVOICING_EXTENSION }} |
| 104 | + |
| 105 | + - name: "Install composer dependencies in invoicing extension" |
| 106 | + run: cd extensions/Invoicing && composer install --no-dev --no-ansi --no-interaction --prefer-dist --ignore-platform-reqs --classmap-authoritative |
| 107 | + |
| 108 | + - name: "Install npm dependencies in invoicing extension" |
| 109 | + run: cd extensions/Invoicing && npm ci |
| 110 | + |
| 111 | + - name: "Activate invoicing extension" |
| 112 | + run: php artisan module:enable Invoicing |
| 113 | + |
| 114 | + - name: "Install npm dependencies" |
| 115 | + run: npm ci |
| 116 | + |
| 117 | + - name: "Build" |
| 118 | + run: npm run build |
| 119 | + |
| 120 | + - name: "Prepare" |
| 121 | + run: | |
| 122 | + platform=${{ matrix.platform }} |
| 123 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 124 | +
|
| 125 | + - name: "Docker meta" |
| 126 | + id: "meta" |
| 127 | + uses: docker/metadata-action@v5 |
| 128 | + with: |
| 129 | + images: | |
| 130 | + ${{ env.DOCKER_REPO }} |
| 131 | +
|
| 132 | + - name: "Login to solidtime OnPremise Registry" |
| 133 | + uses: docker/login-action@v3 |
| 134 | + with: |
| 135 | + registry: registry.on-premise.solidtime.io |
| 136 | + username: ${{ secrets.ONPREMISE_USERNAME }} |
| 137 | + password: ${{ secrets.ONPREMISE_TOKEN }} |
| 138 | + |
| 139 | + - name: "Set up QEMU" |
| 140 | + uses: docker/setup-qemu-action@v3 |
| 141 | + |
| 142 | + - name: "Set up Docker Buildx" |
| 143 | + uses: docker/setup-buildx-action@v3 |
| 144 | + |
| 145 | + - name: "Build and push by digest" |
| 146 | + id: build |
| 147 | + uses: docker/build-push-action@v6 |
| 148 | + with: |
| 149 | + context: . |
| 150 | + file: docker/prod/Dockerfile |
| 151 | + build-args: | |
| 152 | + DOCKER_FILES_BASE_PATH=docker/prod/ |
| 153 | + platforms: ${{ matrix.platform }} |
| 154 | + labels: ${{ steps.meta.outputs.labels }} |
| 155 | + outputs: type=image,"name=${{ env.DOCKER_REPO }}",push-by-digest=true,name-canonical=true,push=true |
| 156 | + cache-from: type=gha |
| 157 | + cache-to: type=gha,mode=max |
| 158 | + |
| 159 | + - name: "Export digest" |
| 160 | + run: | |
| 161 | + mkdir -p ${{ runner.temp }}/digests |
| 162 | + digest="${{ steps.build.outputs.digest }}" |
| 163 | + touch "${{ runner.temp }}/digests/${digest#sha256:}" |
| 164 | +
|
| 165 | + - name: "Upload digest" |
| 166 | + uses: actions/upload-artifact@v4 |
| 167 | + with: |
| 168 | + name: digests-${{ env.PLATFORM_PAIR }} |
| 169 | + path: ${{ runner.temp }}/digests/* |
| 170 | + if-no-files-found: error |
| 171 | + retention-days: 1 |
| 172 | + |
| 173 | + merge: |
| 174 | + runs-on: ubuntu-latest |
| 175 | + timeout-minutes: 90 |
| 176 | + needs: |
| 177 | + - build |
| 178 | + steps: |
| 179 | + - name: "Download digests" |
| 180 | + uses: actions/download-artifact@v4 |
| 181 | + with: |
| 182 | + path: ${{ runner.temp }}/digests |
| 183 | + pattern: digests-* |
| 184 | + merge-multiple: true |
| 185 | + |
| 186 | + - name: "Login to solidtime OnPremise Registry" |
| 187 | + uses: docker/login-action@v3 |
| 188 | + with: |
| 189 | + registry: registry.on-premise.solidtime.io |
| 190 | + username: ${{ secrets.ONPREMISE_USERNAME }} |
| 191 | + password: ${{ secrets.ONPREMISE_TOKEN }} |
| 192 | + |
| 193 | + - name: "Set up Docker Buildx" |
| 194 | + uses: docker/setup-buildx-action@v3 |
| 195 | + |
| 196 | + - name: "Docker meta" |
| 197 | + id: meta |
| 198 | + uses: docker/metadata-action@v5 |
| 199 | + with: |
| 200 | + images: | |
| 201 | + ${{ env.DOCKER_REPO }} |
| 202 | + tags: | |
| 203 | + type=ref,event=branch |
| 204 | + type=ref,event=pr |
| 205 | + type=semver,pattern={{version}} |
| 206 | + type=semver,pattern={{major}}.{{minor}} |
| 207 | +
|
| 208 | + - name: "Create manifest list and push" |
| 209 | + working-directory: ${{ runner.temp }}/digests |
| 210 | + run: | |
| 211 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 212 | + $(printf '${{ env.DOCKER_REPO }}@sha256:%s ' *) |
| 213 | +
|
| 214 | + - name: "Inspect image" |
| 215 | + run: | |
| 216 | + docker buildx imagetools inspect ${{ env.DOCKER_REPO }}:${{ steps.meta.outputs.version }} |
0 commit comments