Skip to content

Commit ec8228e

Browse files
committed
Init
1 parent c3fef22 commit ec8228e

File tree

4 files changed

+161
-0
lines changed

4 files changed

+161
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: 📦 Build CTX Binary
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build-image:
13+
name: 📦 Build and Push Builder Image
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
- name: Set up QEMU
21+
uses: docker/setup-qemu-action@v2
22+
with:
23+
platforms: arm64,amd64
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v2
27+
28+
- name: Login to GitHub Container Registry
29+
if: github.event_name == 'release'
30+
uses: docker/login-action@v3
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Extract metadata for Builder Image
37+
id: builder-metadata
38+
uses: docker/metadata-action@v5
39+
with:
40+
images: ghcr.io/${{ github.repository }}/php-builder
41+
tags: |
42+
type=ref,event=branch
43+
type=ref,event=pr
44+
type=semver,pattern={{version}}
45+
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
46+
47+
- name: Build and Push Builder Image
48+
uses: docker/build-push-action@v4
49+
with:
50+
context: .
51+
platforms: linux/amd64,linux/arm64
52+
push: ${{ github.event_name == 'release' }}
53+
tags: ${{ steps.builder-metadata.outputs.tags }}
54+
labels: ${{ steps.builder-metadata.outputs.labels }}
55+
cache-from: type=gha,scope=builder-image
56+
cache-to: type=gha,mode=max,scope=builder-image

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

Dockerfile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
FROM php:8.3-cli-alpine
2+
3+
# Install required packages
4+
RUN apk add --no-cache \
5+
wget \
6+
git \
7+
unzip \
8+
upx \
9+
bash \
10+
file
11+
12+
# Set working directory
13+
WORKDIR /build-tools
14+
15+
# Clone and set up static-php-cli from source
16+
RUN git clone https://github.com/crazywhalecc/static-php-cli.git --depth=1 /build-tools/static-php-cli \
17+
&& cd /build-tools/static-php-cli \
18+
&& ./bin/setup-runtime
19+
20+
# Download box tool for PHAR creation
21+
RUN wget -O /usr/local/bin/box "https://github.com/box-project/box/releases/download/4.6.6/box.phar" \
22+
&& chmod +x /usr/local/bin/box
23+
24+
# Install UPX for compression
25+
RUN cd /build-tools/static-php-cli && ./bin/spc install-pkg upx
26+
27+
# Make tools available in PATH
28+
ENV PATH="/build-tools/static-php-cli/bin:$PATH"
29+
30+
# Create build directories
31+
RUN mkdir -p /build-tools/build/phar /build-tools/build/bin
32+
33+
# Download required PHP extensions (pre-download to speed up builds)
34+
RUN cd /build-tools/static-php-cli && \
35+
./bin/spc download micro \
36+
--for-extensions=ctype,dom,filter,libxml,mbstring,phar,simplexml,sockets,tokenizer,xml,xmlwriter,curl \
37+
--with-php=8.3 \
38+
--prefer-pre-built
39+
40+
# Verify environment is ready
41+
RUN cd /build-tools/static-php-cli && ./bin/spc doctor --auto-fix
42+
43+
# Pre-build micro.sfx with required extensions (for all supported platforms)
44+
RUN cd /build-tools/static-php-cli && \
45+
./bin/spc build ctype,dom,filter,libxml,mbstring,phar,simplexml,sockets,tokenizer,xml,xmlwriter,curl \
46+
--build-micro \
47+
--with-upx-pack
48+
49+
# Copy the micro.sfx to a known location for later reuse
50+
RUN cp /build-tools/static-php-cli/buildroot/micro.sfx /build-tools/build/bin/
51+
52+
# Set up Composer
53+
COPY --from=composer:2.8.4 /usr/bin/composer /usr/bin/composer
54+
55+
# Default command to display info
56+
CMD ["echo", "PHP Builder image is ready for use"]

Dockerfile.windows

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Use Windows Server Core as the base image
2+
FROM mcr.microsoft.com/windows/servercore:ltsc2022 AS builder
3+
4+
# Define build arguments
5+
ARG VERSION="latest"
6+
7+
# Set PowerShell as the default shell
8+
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
9+
10+
# Set working directory
11+
WORKDIR C:/build
12+
13+
# Install Chocolatey package manager
14+
RUN Set-ExecutionPolicy Bypass -Scope Process -Force; \
15+
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; \
16+
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
17+
18+
# Install required tools
19+
RUN choco install -y git php composer visualstudio2022buildtools visualstudio2022-workload-vctools
20+
21+
# Create build directories
22+
RUN mkdir -p .build/phar .build/bin
23+
24+
# Download box tool for PHAR creation
25+
RUN Invoke-WebRequest -Uri "https://github.com/box-project/box/releases/download/4.6.6/box.phar" -OutFile ".build/bin/box.phar"
26+
27+
# Download static-php-cli for Windows
28+
RUN Invoke-WebRequest -Uri "https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-windows-x64.exe" -OutFile ".build/bin/spc.exe"
29+
30+
# Download required PHP extensions
31+
RUN .build/bin/spc.exe download micro `
32+
--for-extensions=ctype,dom,filter,libxml,mbstring,phar,simplexml,sockets,tokenizer,xml,xmlwriter,curl `
33+
--with-php=8.3 `
34+
--prefer-pre-built
35+
36+
# Install UPX for compression
37+
RUN .build/bin/spc.exe install-pkg upx
38+
39+
# Verify environment is ready
40+
RUN .build/bin/spc.exe doctor --auto-fix
41+
42+
# Build the self-executable binary with required extensions
43+
RUN .build/bin/spc.exe build "ctype,dom,filter,libxml,mbstring,phar,simplexml,sockets,tokenizer,xml,xmlwriter,curl" `
44+
--build-micro `
45+
--with-upx-pack
46+
47+
# Default command to display info
48+
CMD ["echo", "PHP Builder image is ready for use"]

0 commit comments

Comments
 (0)