From 03d40cfe7bba3b5b08bd85007b9659cefafd5a53 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Wed, 15 Feb 2023 00:08:12 +0100 Subject: [PATCH] docker: build and push image --- .github/workflows/push.yaml | 31 +++++++++++++++++++++++++++++++ Dockerfile | 32 ++++++++++++++++++++++++++++++++ bin/build | 2 +- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/push.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml new file mode 100644 index 000000000..9084970aa --- /dev/null +++ b/.github/workflows/push.yaml @@ -0,0 +1,31 @@ +name: push + +on: + push: + tags: + - 'v*' + +jobs: + push: + name: "Build and push ${{ github.ref_name }}" + + runs-on: ubuntu-latest + + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push ${{ matrix.image }} + uses: docker/build-push-action@v4 + with: + context: "{{defaultContext}}:./" + push: true + build-args: VERSION=${{ github.ref_name }} + tags: ghcr.io/deployphp/deployer:${{ github.ref_name }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..d22cafd0e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +## Compile the PHAR +FROM php:8.1-cli-alpine as build + +ENV COMPOSER_ALLOW_SUPERUSER=1 + +# Copy Composer from official image +COPY --from=composer/composer:2-bin /composer /usr/bin/composer + +# Allow to generate .phar files +RUN echo -e "[PHP]\nphar.readonly = Off" >> /usr/local/etc/php/php.ini + +WORKDIR /app/ + +# Copy sources files +COPY ./ /app/ + +ARG VERSION + +# Install dependencies and build PHAR +RUN composer install --no-dev --quiet && /app/bin/build -v$VERSION + + +# Copy the PHAR file in the final image +FROM php:8.1-cli-alpine + +COPY --from=build /app/deployer.phar /usr/local/bin/deployer + +## Make deployer executable and check that it can be executed +RUN chmod +x /usr/local/bin/deployer && deployer --version + +# Call deployer automatically +ENTRYPOINT ["/usr/local/bin/deployer"] diff --git a/bin/build b/bin/build index 7b4637627..eea8e6388 100755 --- a/bin/build +++ b/bin/build @@ -15,7 +15,7 @@ $version = 'dev-master'; if (array_key_exists('v', $opt)) { $version = $opt['v']; if (!preg_match('/^\d+\.\d+\.\d+(-[\d\w\.]+)?$/i', $version)) { - die("Version number must follow semantic versioning.\n"); + die("Version number must follow semantic versioning, '$version' given.\n"); } }