diff --git a/.docker/Dockerfile b/.docker/Dockerfile new file mode 100644 index 000000000..9cc0c500b --- /dev/null +++ b/.docker/Dockerfile @@ -0,0 +1,8 @@ +FROM php:8.1-cli-alpine + +COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ +RUN install-php-extensions zlib phar sodium tokenizer filter + +COPY bin/box.phar /box.phar + +ENTRYPOINT ["/box.phar"] diff --git a/.docker/php81_build_phar b/.docker/php81_build_phar new file mode 100644 index 000000000..a07175968 --- /dev/null +++ b/.docker/php81_build_phar @@ -0,0 +1,19 @@ +FROM php:8.1-cli-alpine as build-stage + +RUN apk add --update make git + +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +RUN mkdir -p /opt/box-project/box +WORKDIR /opt/box-project/box +ADD . /opt/box-project/box +RUN cd /opt/box-project/box && \ + make compile + +FROM php:8.1-cli-alpine + +COPY --from=build-stage /opt/box-project/box/bin/box.phar /usr/bin/box + +RUN mkdir -p /local +WORKDIR /local +ENTRYPOINT ["/usr/bin/box"] \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2ec35fe41..94c621e6a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -7,6 +7,10 @@ on: release: types: [ created ] +env: + DOCKERFILE: .docker/Dockerfile + DOCKERHUB_USERNAME: boxproject + jobs: build-phar: runs-on: ubuntu-latest @@ -93,3 +97,60 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} tap: box-project/homebrew-box formula: humbug/box + + publish-docker-image: + runs-on: ubuntu-latest + name: Publish PHAR + needs: + - build-phar + if: github.event_name == 'release' + steps: + - uses: actions/download-artifact@v3 + with: + name: box-phar + path: . + + # See https://github.com/actions/download-artifact#limitations + # the permissions are not guaranteed to be preserved + - name: Ensure PHAR is executable + run: chmod 755 bin/box.phar + + - name: Check that the PHAR works + run: bin/box.phar --ansi --version + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to Docker Container Registry + uses: docker/login-action@v2 + with: + username: ${{ env.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and export to Docker + uses: docker/build-push-action@v3 + with: + context: . + file: ${{ env.DOCKERFILE }} + platforms: linux/amd64 + tags: | + ${{ env.DOCKERHUB_USERNAME }}/box:${{ steps.download_release.outputs.version }} + ${{ env.DOCKERHUB_USERNAME }}/box:latest + load: true + + - name: Test the image + run: docker run --rm ${{ env.DOCKERHUB_USERNAME }}/box:latest --version + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + file: ${{ env.DOCKERFILE }} + platforms: linux/amd64 + tags: | + ${{ env.DOCKERHUB_USERNAME }}/box:${{ steps.download_release.outputs.version }} + ${{ env.DOCKERHUB_USERNAME }}/box:latest + push: true