Skip to content

Commit 987388e

Browse files
committed
ci: init docker images
0 parents  commit 987388e

5 files changed

Lines changed: 227 additions & 0 deletions

File tree

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
indent_style = space
13+
indent_size = 2
14+
15+
[*.{diff,md}]
16+
trim_trailing_whitespace = false
17+
insert_final_newline = false

.github/workflows/build-php.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Build PHP Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- php/**
9+
pull_request:
10+
branches:
11+
- main
12+
paths:
13+
- php/**
14+
15+
16+
env:
17+
# Use docker.io for Docker Hub if empty
18+
REGISTRY: ghcr.io
19+
# github.repository as <account>/<repo>
20+
IMAGE_NAME: yieldstudio/php
21+
22+
jobs:
23+
matrix:
24+
runs-on: ubuntu-latest
25+
outputs:
26+
php_versions: ${{ steps.set.outputs.php_versions }}
27+
type: ${{ steps.set.outputs.type }}
28+
dockerfile: ${{ steps.set.outputs.dockerfile }}
29+
steps:
30+
- name: Set PHP versions
31+
id: set
32+
run: |
33+
echo 'php_versions=["8.2","8.3","8.4"]' >> $GITHUB_OUTPUT
34+
echo 'type=["unit"]' >> $GITHUB_OUTPUT
35+
echo 'dockerfile=["unit.Dockerfile"]' >> $GITHUB_OUTPUT
36+
37+
build:
38+
needs: matrix
39+
runs-on: ubuntu-latest
40+
permissions:
41+
contents: read
42+
packages: write
43+
id-token: write
44+
env:
45+
NODE_VERSION: '22'
46+
strategy:
47+
matrix:
48+
php_version: ${{ fromJSON(needs.matrix.outputs.php_versions) }}
49+
type: ${{ fromJSON(needs.matrix.outputs.type) }}
50+
dockerfile: ${{ fromJSON(needs.matrix.outputs.dockerfile) }}
51+
steps:
52+
- name: Checkout code
53+
uses: actions/checkout@v4
54+
55+
- name: Set up QEMU
56+
uses: docker/setup-qemu-action@v3
57+
58+
- name: Set up Docker Buildx
59+
uses: docker/setup-buildx-action@v3
60+
61+
- name: Log into registry ${{ env.REGISTRY }}
62+
if: github.event_name != 'pull_request'
63+
uses: docker/login-action@v3
64+
with:
65+
registry: ${{ env.REGISTRY }}
66+
username: ${{ github.actor }}
67+
password: ${{ secrets.GITHUB_TOKEN }}
68+
69+
- name: Extract Docker metadata
70+
id: meta
71+
uses: docker/metadata-action@v4
72+
with:
73+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
74+
tags: |
75+
type=ref,event=branch,prefix=${{ matrix.php_version }}-${{ matrix.type }}-latest-
76+
type=ref,event=tag,prefix=${{ matrix.php_version }}-${{ matrix.type }}-v
77+
type=sha
78+
type=raw,${{ matrix.php_version }}-${{ matrix.type }}
79+
80+
- name: Build docker image
81+
uses: docker/build-push-action@v6
82+
with:
83+
context: ./php
84+
file: ./php/${{ matrix.dockerfile }}
85+
build-args: |
86+
PHP_VERSION=${{ matrix.php_version }}
87+
NODE_VERSION=${{ env.NODE_VERSION }}
88+
platforms: linux/amd64,linux/arm64
89+
cache-from: type=gha,scope=php-${{ matrix.php_version }}-${{ matrix.type }}
90+
cache-to: type=gha,scope=php-${{ matrix.php_version }}-${{ matrix.type }},mode=max
91+
push: ${{ github.event_name != 'pull_request' }}
92+
tags: |
93+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.php_version }}-${{ matrix.type }}
94+
${{ steps.meta.outputs.tags }}
95+
labels: ${{ steps.meta.outputs.labels }}
96+
97+
scan:
98+
needs:
99+
- matrix
100+
- build
101+
runs-on: ubuntu-latest
102+
strategy:
103+
matrix:
104+
php_version: ${{ fromJSON(needs.matrix.outputs.php_versions) }}
105+
type: ${{ fromJSON(needs.matrix.outputs.type) }}
106+
dockerfile: ${{ fromJSON(needs.matrix.outputs.dockerfile) }}
107+
steps:
108+
- name: Checkout Code
109+
uses: actions/checkout@v4
110+
111+
- name: Run Trivy Vulnerability Scan
112+
uses: aquasecurity/trivy-action@0.31.0
113+
with:
114+
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.php_version }}-${{ matrix.type }}
115+
format: 'sarif'
116+
output: 'trivy-results.sarif'
117+
118+
- name: Upload Trivy scan results to GitHub Security tab
119+
uses: github/codeql-action/upload-sarif@v3
120+
if: always()
121+
with:
122+
sarif_file: 'trivy-results.sarif'
123+
124+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/sh
2+
script_name="filament-automations"
3+
4+
# Set default values for Laravel automations
5+
: "${AUTORUN_ENABLED:=false}"
6+
7+
if [ "$DISABLE_DEFAULT_CONFIG" = "false" ]; then
8+
# Check to see if an Artisan file exists and assume it means Laravel is configured.
9+
if [ -f "$APP_BASE_DIR/artisan" ] && [ "$AUTORUN_ENABLED" = "true" ]; then
10+
echo "Checking for Filament automations..."
11+
############################################################################
12+
# artisan icons:cache
13+
############################################################################
14+
if [ "${AUTORUN_LARAVEL_ICONS:=true}" = "true" ]; then
15+
set +e
16+
echo "🚀 Caching Blade Icons..."
17+
php "$APP_BASE_DIR/artisan" icons:cache
18+
if [ $? -eq 0 ]; then
19+
echo "✅ Blade Icons cached successfully."
20+
else
21+
echo "❌ Failed to cache Blade Icons."
22+
fi
23+
set -e
24+
fi
25+
26+
############################################################################
27+
# artisan filament:optimize
28+
############################################################################
29+
if [ "${AUTORUN_LARAVEL_FILAMENT_OPTIMIZE:=true}" = "true" ]; then
30+
set +e
31+
echo "🚀 Optimizing Filament..."
32+
php "$APP_BASE_DIR/artisan" filament:optimize
33+
if [ $? -eq 0 ]; then
34+
echo "✅ Filament optimized successfully."
35+
else
36+
echo "❌ Failed to optimize Filament."
37+
fi
38+
set -e
39+
fi
40+
fi
41+
else
42+
if [ "$LOG_OUTPUT_LEVEL" = "debug" ]; then
43+
echo "👉 $script_name: DISABLE_DEFAULT_CONFIG does not equal 'false', so automations will NOT be performed."
44+
fi
45+
fi
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
script_name="db-endpoint-automations"
3+
4+
# Set default values for Laravel automations
5+
: "${AUTORUN_ENABLED:=false}"
6+
7+
if [ "$DISABLE_DEFAULT_CONFIG" = "false" ]; then
8+
# Check if DB_ENDPOINT is set
9+
if [ -n "$DB_ENDPOINT" ] then
10+
export DB_CONNECTION="pgsql"
11+
export DB_HOST="$(echo "$DB_ENDPOINT" | sed -E 's|^postgres://([^:]+):.*|\1|')"
12+
export DB_PORT="$(echo "$DB_ENDPOINT" | sed -E 's|^postgres://[^:]+:([^/]+).*|\1|')"
13+
export DB_DATABASE="$(echo "$DB_ENDPOINT" | sed -E 's|^postgres://[^/]+/([^?]+).*|\1|')"
14+
else
15+
echo "No DB endpoint set or autorun is disabled."
16+
fi
17+
else
18+
if [ "$LOG_OUTPUT_LEVEL" = "debug" ]; then
19+
echo "👉 $script_name: DISABLE_DEFAULT_CONFIG does not equal 'false', so automations will NOT be performed."
20+
fi
21+
fi

php/unit.Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ARG PHP_VERSION=
2+
ARG NODE_VERSION=
3+
4+
############################################
5+
# Base Image
6+
############################################
7+
FROM serversideup/php:${PHP_VERSION}-unit AS base
8+
9+
ENV SSL_MODE=off
10+
ENV AUTORUN_ENABLED=true
11+
ENV PHP_OPCACHE_ENABLE=1
12+
13+
COPY --chmod=755 ./entrypoint.d/ /etc/entrypoint.d/
14+
15+
USER root
16+
17+
WORKDIR /var/www/html/
18+
RUN apt-get update \
19+
&& apt-get install -y git \
20+
&& install-php-extensions exif gd intl

0 commit comments

Comments
 (0)