diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5d92f00 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,40 @@ +name: Build Docker Image + +on: + push: + paths: + - build.sh + - .github/workflows/build.yml + workflow_dispatch: + +permissions: + contents: read + packages: write + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - arch: amd64 + - arch: arm64 + steps: + - name: Clone + uses: actions/checkout@v4 + + - name: Install Chisel + uses: shyim/chisel-installer@main + + - name: Build image + run: ./build.sh ${{ matrix.arch }} --push + merge: + needs: [build] + runs-on: ubuntu-latest + steps: + - name: Login into Github Docker Registery + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - run: docker manifest create friendsofshopware/code-style:latest --amend friendsofshopware/code-style-amd64 --amend friendsofshopware/code-style-arm64 + + - run: docker manifest push friendsofshopware/code-style:latest \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5954808..e72c03f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ vendor .php-cs-fixer.cache +/db +/rootfs diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e2dffab --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM --platform=$BUILDPLATFORM composer as download + +ADD . /cs-fix +WORKDIR /cs-fix +RUN composer install --no-dev --no-interaction --no-progress --no-suggest --optimize-autoloader +RUN echo 'memory_limit = -1' > /php.ini + +FROM scratch + +LABEL org.opencontainers.image.authors="FriendsOfShopware" \ + org.opencontainers.image.url="https://github.com/FriendsOfShopware/code-style" \ + org.opencontainers.image.source="https://github.com/FriendsOfShopware/code-style" \ + org.opencontainers.image.vendor="FriendsOfShopware" \ + org.opencontainers.image.licenses="MIT" \ + org.opencontainers.image.title="PHP-CS-Fixer" +COPY rootfs/ / + +COPY --from=download /cs-fix /cs-fix +COPY --from=download /php.ini /etc/php/8.2/cli/conf.d/99-memory-limit.ini +ENTRYPOINT ["/usr/bin/php", "/cs-fix/bin/frosh-cs", "fix"] \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..ea54244 --- /dev/null +++ b/build.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +set -eo pipefail + +arch=$1 +params=$2 + +if [ -z "$arch" ]; then + echo "Usage: $0 " + exit 1 +fi + +echo "Building version $version" + +rm -rf rootfs +mkdir rootfs + +if [[ ! -d db ]]; then + git clone -b ubuntu-23.10-php https://github.com/shyim/chisel-releases.git db +fi + +chisel cut --arch=$arch --release ./db --root rootfs/ php8.2-cli_base php8.2-common_all-cli php8.2-common_phar-cli php8.2-mbstring_cli php8.2-xml_dom-cli dash_bins + +docker build --platform "linux/${arch}" -t "friendsofshopware/code-style:${version}-${arch}" . + +if [[ "$params" == "--push" ]]; then + docker push "friendsofshopware/code-style:${version}-${arch}" +fi