Skip to content

Commit

Permalink
docker: build and push image
Browse files Browse the repository at this point in the history
  • Loading branch information
alexislefebvre committed Feb 14, 2023
1 parent c4380ef commit bf1892e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Compile the PHAR in the first multi-stage image ##
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, the "v" in the version (e.g. "v6.9.4")
# will provide the "v" arg and its value directly
RUN composer install --no-dev --quiet && /app/bin/build -$VERSION \
# The file should exist
&& ls -lh /app/deployer.phar


## Create the final image ##
FROM php:8.1-cli-alpine

# Copy the PHAR file from the first multi-stage image to the final image
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"]
2 changes: 1 addition & 1 deletion bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down

0 comments on commit bf1892e

Please sign in to comment.