Skip to content

Commit 0920053

Browse files
committed
- split binary builds by os type.
- add docker build for amd64 and arm64 platforms
1 parent 0f24155 commit 0920053

File tree

3 files changed

+277
-141
lines changed

3 files changed

+277
-141
lines changed
+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
---
2+
3+
name: 📦 Build Linux binary
4+
5+
on: # yamllint disable-line rule:truthy
6+
release:
7+
types:
8+
- published
9+
10+
jobs:
11+
build-linux:
12+
runs-on: ubuntu-latest
13+
name: 📦 Build Linux Executables
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
platform:
18+
- os: linux
19+
arch: amd64
20+
- os: linux
21+
arch: arm64
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v3
26+
27+
- name: Set up QEMU
28+
uses: docker/setup-qemu-action@v2
29+
with:
30+
platforms: arm64,amd64
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v2
34+
35+
- name: Extract version from tag
36+
id: get_version
37+
run: |
38+
if [[ "$GITHUB_REF_NAME" == refs/pull/* ]]; then
39+
# For pull requests, use "dev" as version
40+
VERSION="dev"
41+
else
42+
# For releases, extract version from tag (remove 'v' prefix if present)
43+
VERSION=${GITHUB_REF_NAME#v}
44+
fi
45+
echo "VERSION=$VERSION" >> $GITHUB_ENV
46+
echo "{\"version\": \"$VERSION\", \"type\":\"bin\"}" > version.json
47+
48+
- name: Build Docker image for ${{ matrix.platform.os }}-${{ matrix.platform.arch }}
49+
uses: docker/build-push-action@v4
50+
with:
51+
context: .
52+
push: false
53+
load: true
54+
tags: ctx-builder-${{ matrix.platform.os }}-${{ matrix.platform.arch }}:latest
55+
platforms: linux/${{ matrix.platform.arch }}
56+
build-args: |
57+
TARGET_OS=${{ matrix.platform.os }}
58+
TARGET_ARCH=${{ matrix.platform.arch }}
59+
VERSION=${{ env.VERSION }}
60+
cache-from: type=gha,scope=${{ matrix.platform.os }}-${{ matrix.platform.arch }}
61+
cache-to: type=gha,mode=max,scope=${{ matrix.platform.os }}-${{ matrix.platform.arch }}
62+
63+
- name: Extract executable
64+
run: |
65+
mkdir -p dist
66+
container_id=$(docker create ctx-builder-${{ matrix.platform.os }}-${{ matrix.platform.arch }}:latest)
67+
docker cp $container_id:/.output/ctx ./dist/ctx-${{ env.VERSION }}-${{ matrix.platform.os }}-${{ matrix.platform.arch }}
68+
docker rm $container_id
69+
70+
- name: 📤 Upload release assets
71+
uses: softprops/[email protected]
72+
if: startsWith(github.ref, 'refs/tags/')
73+
with:
74+
token: "${{ secrets.RELEASE_TOKEN }}"
75+
files: |
76+
./dist/ctx-${{ env.VERSION }}-${{ matrix.platform.os }}-${{ matrix.platform.arch }}
77+
78+
build-alpine-docker:
79+
needs: [ build-linux ]
80+
runs-on: ubuntu-latest
81+
name: 📦 Build Alpine Docker Container
82+
steps:
83+
- name: Checkout code
84+
uses: actions/checkout@v3
85+
86+
- name: Set up QEMU
87+
uses: docker/setup-qemu-action@v2
88+
with:
89+
platforms: arm64,amd64
90+
91+
- name: Set up Docker Buildx
92+
uses: docker/setup-buildx-action@v2
93+
94+
- name: Extract version from tag
95+
id: get_version
96+
run: |
97+
if [[ "$GITHUB_REF_NAME" == refs/pull/* ]]; then
98+
# For pull requests, use "dev" as version
99+
VERSION="dev"
100+
else
101+
# For releases, extract version from tag (remove 'v' prefix if present)
102+
VERSION=${GITHUB_REF_NAME#v}
103+
fi
104+
echo "VERSION=$VERSION" >> $GITHUB_ENV
105+
106+
- name: Download Linux AMD64 binary
107+
uses: actions/download-artifact@v3
108+
with:
109+
name: ctx-${{ env.VERSION }}-linux-amd64
110+
path: ./tmp/amd64
111+
112+
- name: Download Linux ARM64 binary
113+
uses: actions/download-artifact@v3
114+
with:
115+
name: ctx-${{ env.VERSION }}-linux-arm64
116+
path: ./tmp/arm64
117+
118+
- name: Make binaries executable
119+
run: |
120+
chmod +x ./tmp/amd64/ctx-${{ env.VERSION }}-linux-amd64
121+
chmod +x ./tmp/arm64/ctx-${{ env.VERSION }}-linux-arm64
122+
123+
- name: Create Docker context directory
124+
run: |
125+
mkdir -p ./docker/amd64 ./docker/arm64
126+
cp ./tmp/amd64/ctx-${{ env.VERSION }}-linux-amd64 ./docker/amd64/ctx
127+
cp ./tmp/arm64/ctx-${{ env.VERSION }}-linux-arm64 ./docker/arm64/ctx
128+
129+
# Create Dockerfile for AMD64
130+
cat > ./docker/amd64/Dockerfile << 'EOF'
131+
FROM alpine:3.19
132+
133+
RUN apk add --no-cache libstdc++ libgcc
134+
135+
WORKDIR /app
136+
137+
COPY ctx /usr/local/bin/ctx
138+
139+
RUN chmod +x /usr/local/bin/ctx
140+
141+
ENTRYPOINT ["ctx"]
142+
EOF
143+
144+
# Create Dockerfile for ARM64
145+
cat > ./docker/arm64/Dockerfile << 'EOF'
146+
FROM alpine:3.19
147+
148+
RUN apk add --no-cache libstdc++ libgcc
149+
150+
WORKDIR /app
151+
152+
COPY ctx /usr/local/bin/ctx
153+
154+
RUN chmod +x /usr/local/bin/ctx
155+
156+
ENTRYPOINT ["ctx"]
157+
EOF
158+
159+
- name: Extract metadata for Docker Image
160+
id: docker-metadata
161+
uses: docker/metadata-action@v5
162+
with:
163+
images: ghcr.io/${{ github.repository }}/ctx
164+
tags: |
165+
type=ref,event=branch
166+
type=ref,event=pr
167+
type=semver,pattern={{version}}
168+
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
169+
170+
- name: Login to GitHub Container Registry
171+
uses: docker/login-action@v3
172+
with:
173+
registry: ghcr.io
174+
username: ${{ secrets.GHCR_LOGIN }}
175+
password: ${{ secrets.GHCR_PASSWORD }}
176+
177+
- name: Build and push Docker image for AMD64
178+
uses: docker/build-push-action@v4
179+
with:
180+
context: ./docker/amd64
181+
push: true
182+
tags: ${{ steps.docker-metadata.outputs.tags }}
183+
labels: ${{ steps.docker-metadata.outputs.labels }}
184+
platforms: linux/amd64
185+
186+
- name: Build and push Docker image for ARM64
187+
uses: docker/build-push-action@v4
188+
with:
189+
context: ./docker/arm64
190+
push: true
191+
tags: ${{ steps.docker-metadata.outputs.tags }}
192+
labels: ${{ steps.docker-metadata.outputs.labels }}
193+
platforms: linux/amd64

.github/workflows/buld-bin-release.yml renamed to .github/workflows/build-macos-release.yml

+1-141
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,13 @@
11
---
22

3-
name: 📦 Build binary
3+
name: 📦 Build Macos binary
44

55
on: # yamllint disable-line rule:truthy
66
release:
77
types:
88
- published
99

1010
jobs:
11-
build-unix:
12-
runs-on: ubuntu-latest
13-
name: 📦 Build Unix Executables
14-
strategy:
15-
fail-fast: false
16-
matrix:
17-
platform:
18-
- os: linux
19-
arch: amd64
20-
- os: linux
21-
arch: arm64
22-
23-
steps:
24-
- name: Checkout code
25-
uses: actions/checkout@v3
26-
27-
- name: Set up QEMU
28-
uses: docker/setup-qemu-action@v2
29-
with:
30-
platforms: arm64,amd64
31-
32-
- name: Set up Docker Buildx
33-
uses: docker/setup-buildx-action@v2
34-
35-
- name: Extract version from tag
36-
id: get_version
37-
run: |
38-
if [[ "$GITHUB_REF_NAME" == refs/pull/* ]]; then
39-
# For pull requests, use "dev" as version
40-
VERSION="dev"
41-
else
42-
# For releases, extract version from tag (remove 'v' prefix if present)
43-
VERSION=${GITHUB_REF_NAME#v}
44-
fi
45-
echo "VERSION=$VERSION" >> $GITHUB_ENV
46-
echo "{\"version\": \"$VERSION\", \"type\":\"bin\"}" > version.json
47-
48-
- name: Build Docker image for ${{ matrix.platform.os }}-${{ matrix.platform.arch }}
49-
uses: docker/build-push-action@v4
50-
with:
51-
context: .
52-
push: false
53-
load: true
54-
tags: ctx-builder-${{ matrix.platform.os }}-${{ matrix.platform.arch }}:latest
55-
platforms: linux/${{ matrix.platform.arch }}
56-
build-args: |
57-
TARGET_OS=${{ matrix.platform.os }}
58-
TARGET_ARCH=${{ matrix.platform.arch }}
59-
VERSION=${{ env.VERSION }}
60-
cache-from: type=gha,scope=${{ matrix.platform.os }}-${{ matrix.platform.arch }}
61-
cache-to: type=gha,mode=max,scope=${{ matrix.platform.os }}-${{ matrix.platform.arch }}
62-
63-
- name: Extract executable
64-
run: |
65-
mkdir -p dist
66-
container_id=$(docker create ctx-builder-${{ matrix.platform.os }}-${{ matrix.platform.arch }}:latest)
67-
docker cp $container_id:/.output/ctx ./dist/ctx-${{ env.VERSION }}-${{ matrix.platform.os }}-${{ matrix.platform.arch }}
68-
docker rm $container_id
69-
70-
- name: 📤 Upload release assets
71-
uses: softprops/[email protected]
72-
if: startsWith(github.ref, 'refs/tags/')
73-
with:
74-
token: "${{ secrets.RELEASE_TOKEN }}"
75-
files: |
76-
./dist/ctx-${{ env.VERSION }}-${{ matrix.platform.os }}-${{ matrix.platform.arch }}
77-
7811
build-macos-arm64:
7912
runs-on: macos-14
8013
name: 📦 Build macOS ARM64
@@ -270,76 +203,3 @@ jobs:
270203
files: |
271204
dist/ctx-${{ env.VERSION }}-darwin-amd64
272205
273-
build-windows:
274-
runs-on: windows-latest
275-
name: 📦 Build Windows (x64)
276-
steps:
277-
- name: Checkout code
278-
uses: actions/checkout@v3
279-
280-
- name: Set up PHP
281-
uses: shivammathur/setup-php@v2
282-
with:
283-
php-version: '8.3'
284-
extensions: mbstring, xml, curl, sockets
285-
coverage: none
286-
287-
- name: Extract version from tag or set dev version
288-
id: get_version
289-
shell: bash
290-
run: |
291-
if [[ "$GITHUB_REF" == refs/pull/* ]]; then
292-
# For pull requests, use "dev" as version
293-
VERSION="dev"
294-
else
295-
# For releases, extract version from tag (remove 'v' prefix if present)
296-
VERSION=${GITHUB_REF_NAME#v}
297-
fi
298-
echo "VERSION=$VERSION" >> $GITHUB_ENV
299-
echo "{\"version\": \"$VERSION\", \"type\":\"bin\"}" > version.json
300-
301-
- name: Install Composer dependencies
302-
run: composer install --no-dev --prefer-dist --ignore-platform-reqs
303-
304-
- name: Create build directories
305-
run: New-Item -Path ".build\phar", ".build\bin" -ItemType Directory -Force
306-
307-
- name: Download box tool
308-
run: |
309-
Invoke-WebRequest -Uri "https://github.com/box-project/box/releases/download/4.6.6/box.phar" -OutFile ".build/bin/box.phar"
310-
311-
- name: Download SPC for Windows
312-
run: |
313-
Invoke-WebRequest -Uri "https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-windows-x64.exe" -OutFile ".build/bin/spc.exe"
314-
315-
- name: Download required PHP extensions
316-
run: .build/bin/spc.exe download micro --for-extensions=ctype,dom,filter,libxml,mbstring,phar,simplexml,sockets,tokenizer,xml,xmlwriter,curl --with-php=8.3 --prefer-pre-built
317-
318-
# todo: fix this
319-
# - name: Install UPX for compression
320-
# run: |
321-
# .build/bin/spc.exe install-pkg upx
322-
323-
- name: Verify environment is ready
324-
run: |
325-
.build/bin/spc.exe doctor --auto-fix
326-
327-
- name: Build the self-executable binary
328-
run: .build/bin/spc.exe build "ctype,dom,filter,libxml,mbstring,phar,simplexml,sockets,tokenizer,xml,xmlwriter,curl" --build-micro # --with-upx-pack
329-
330-
- name: Build PHAR file
331-
run: |
332-
php .build/bin/box.phar compile -v
333-
334-
- name: Combine micro.sfx with the PHAR
335-
run: |
336-
New-Item -Path "dist" -ItemType Directory -Force
337-
.build\bin\spc.exe micro:combine .build\phar\ctx.phar --output=dist\ctx-${{ env.VERSION }}-windows-amd64.exe
338-
339-
- name: 📤 Upload release assets
340-
uses: softprops/[email protected]
341-
if: startsWith(github.ref, 'refs/tags/')
342-
with:
343-
token: "${{ secrets.RELEASE_TOKEN }}"
344-
files: |
345-
./dist/ctx-${{ env.VERSION }}-windows-amd64.exe

0 commit comments

Comments
 (0)