Skip to content

Commit

Permalink
feat: publish a docker image on release (#853)
Browse files Browse the repository at this point in the history
I unfortunately could not take the username `humbug` which would match the namespace for the packagist package, and docker hub does not accept dashes nor less than 4 character usernames.

So the final name picked is `boxproject`.

This PR is a rebased version of #694.

Closes #694.
Closes #693.

Co-authored-by: Daniel Reiche <daniel.reiche@check24.de>
  • Loading branch information
theofidry and bassmans-check committed Jan 30, 2023
1 parent cfd4273 commit 22c6ebe
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 19 additions & 0 deletions .docker/php81_build_phar
Original file line number Diff line number Diff line change
@@ -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"]
61 changes: 61 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
release:
types: [ created ]

env:
DOCKERFILE: .docker/Dockerfile
DOCKERHUB_USERNAME: boxproject

jobs:
build-phar:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -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

0 comments on commit 22c6ebe

Please sign in to comment.