Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker image #11307

Open
wants to merge 12 commits into
base: 6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Build docker image

on:
push:
branches:
- add_docker_image
release:
types:
- published

permissions:
contents: read

jobs:
pre_job:
permissions:
actions: write
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v5.3.1
with:
concurrent_skipping: always
cancel_others: true
do_not_skip: '["release"]'
# list files that may affect or are included into the built phar
paths: '["bin/**", "assets/**", "build/**", "dictionaries/**", "src/**", "stubs/**", "psalm", "psalm-language-server", "psalm-plugin", "psalm-refactor", "psalm-review", "psalter", "box.json.dist", "composer.json", "config.xsd", "keys.asc.gpg", "scoper.inc.php"]'

build-docker:
permissions:
packages: write
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
runs-on: ubuntu-latest
steps:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
tools: composer:v2
coverage: none
env:
fail-fast: true

- uses: actions/checkout@v4
with:
fetch-depth: 0 # required for composer to automatically detect root package version

- name: Get Composer Cache Directories
id: composer-cache
run: |
echo "files_cache=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
echo "vcs_cache=$(composer config cache-vcs-dir)" >> $GITHUB_OUTPUT

- name: Generate composer.lock
run: |
composer update --no-install

- name: Cache composer cache
uses: actions/cache@v4
with:
path: |
${{ steps.composer-cache.outputs.files_cache }}
${{ steps.composer-cache.outputs.vcs_cache }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Run composer install
run: composer install -o
# DO NOT set this, we need composer to figure out the version itself
# env:
# COMPOSER_ROOT_VERSION: dev-master

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Upload docker image
env:
EVENT_NAME: ${{ github.event_name }}
REF: ${{ github.ref }}
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
php bin/ci/build-docker.php
57 changes: 57 additions & 0 deletions bin/ci/build-docker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols, Generic.Files.LineLength.TooLong


declare(strict_types=1);

use Amp\Process\Process;

use function Amp\ByteStream\getStderr;
use function Amp\ByteStream\getStdout;
use function Amp\ByteStream\pipe;
use function Amp\async;

require 'vendor/autoload.php';

$commit = getenv('GITHUB_SHA');
$ref = substr(getenv('REF'), strlen('refs/heads/'));
$is_tag = getenv('EVENT_NAME') === 'release';

echo "Waiting for commit $commit on $ref...".PHP_EOL;

function r(string $cmd): void
{
getStderr()->write("> $cmd\n");
$cmd = Process::start($cmd);
async(pipe(...), $cmd->getStdout(), getStdout())->ignore();
async(pipe(...), $cmd->getStderr(), getStderr())->ignore();
$cmd->join();
}

$composer_branch = $is_tag ? $ref : "dev-$ref";
$dev = $is_tag ? '' : '~dev';

$cur = 0;
while (true) {
$json = json_decode(file_get_contents("https://repo.packagist.org/p2/vimeo/psalm$dev.json?v=$cur"), true)["packages"]["vimeo/psalm"];
foreach ($json as $v) {
if ($v['version'] === $composer_branch) {
if ($v['source']['reference'] === $commit) {
break 2;
}
break;
}
}
sleep(1);
$cur++;
}

$ref = escapeshellarg($ref);
$composer_branch = escapeshellarg($composer_branch);

passthru("docker buildx build --platform linux/amd64,linux/arm64/v8 . -t ghcr.io/vimeo/psalm:$ref --build-arg PSALM_REV=$composer_branch -f bin/docker/Dockerfile");
passthru("docker push ghcr.io/vimeo/psalm:$ref");

if ($is_tag) {
passthru("docker tag ghcr.io/vimeo/psalm:$ref ghcr.io/vimeo/psalm:latest");
passthru("docker push ghcr.io/vimeo/psalm:latest");
}
Loading
Loading