Skip to content

Commit d9e13ab

Browse files
committed
TUN-9803: Add windows builds to gitlab-ci
1 parent 9e6d58a commit d9e13ab

19 files changed

+443
-216
lines changed

.ci/ci-image.gitlab-ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Builds a custom CI Image when necessary
2+
3+
include:
4+
#####################################################
5+
############## Build and Push CI Image ##############
6+
#####################################################
7+
- component: $CI_SERVER_FQDN/cloudflare/ci/docker-image/build-push-image@~latest
8+
inputs:
9+
stage: pre-build
10+
jobPrefix: ci-image
11+
# runOnChangesTo: [".ci/image/**"]
12+
# runOnMR: true
13+
# runOnBranches: '^master$'
14+
runOnBranches: "^.+$"
15+
commentImageRefs: false
16+
runner: vm-linux-x86-4cpu-8gb
17+
EXTRA_DIB_ARGS: "--manifest=.ci/image/.docker-images"
18+
19+
#####################################################
20+
## Resolve the image reference for downstream jobs ##
21+
#####################################################
22+
- component: $CI_SERVER_FQDN/cloudflare/ci/docker-image/get-image-ref@~latest
23+
inputs:
24+
stage: pre-build
25+
jobPrefix: ci-image
26+
# runOnMR: true
27+
# runOnBranches: '^master$'
28+
runOnBranches: "^.+$"
29+
IMAGE_PATH: "$REGISTRY_HOST/stash/tun/cloudflared/ci-image/master"
30+
VARIABLE_NAME: BUILD_IMAGE
31+
needs:
32+
- job: ci-image-build-push-image
33+
optional: true

.ci/commons.gitlab-ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## A set of predefined rules to use on the different jobs
2+
.default-rules:
3+
# Rules to run the job only on the master branch
4+
run-on-master:
5+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
6+
when: always
7+
- when: never
8+
# Rules to run the job only on branches that are not master. This is needed because for now
9+
# we need to keep a similar behavior due to the integration with teamcity, which requires us
10+
# to not trigger pipelines on tags and/or merge requests.
11+
run-on-branch:
12+
- if: $CI_COMMIT_TAG
13+
when: never
14+
- if: $CI_PIPELINE_SOURCE != "merge_request_event" && $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
15+
when: always
16+
- when: never
17+
18+
# This before_script is injected into every job that runs on master meaning that if there is no tag the step
19+
# will succeed but only write "No tag present - Skipping" to the console.
20+
.check-tag:
21+
before_script:
22+
- |
23+
# Check if there is a Git tag pointing to HEAD
24+
echo "Tag found: $(git tag --points-at HEAD | grep .)"
25+
if git tag --points-at HEAD | grep .; then
26+
echo "Tag found: $(git tag --points-at HEAD | grep .)"
27+
export "VERSION=$(git tag --points-at HEAD | grep .)"
28+
else
29+
echo "No tag present — skipping."
30+
exit 0
31+
fi

.ci/image/.docker-images

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
images:
2+
- name: ci-image

.ci/image/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ARG CLOUDFLARE_DOCKER_REGISTRY_HOST
2+
3+
FROM ${CLOUDFLARE_DOCKER_REGISTRY_HOST:-registry.cfdata.org}/stash/cf/debian-images/bookworm/main:2025.7.0@sha256:6350da2f7e728dae2c1420f6dafc38e23cacc0b399d3d5b2f40fe48d9c8ff1ca
4+
5+
RUN apt-get update && \
6+
apt-get upgrade -y && \
7+
apt-get install --no-install-recommends --allow-downgrades -y \
8+
build-essential \
9+
git \
10+
go-boring=1.24.4-1 \
11+
libffi-dev \
12+
python3-dev \
13+
python3-pip \
14+
python3-setuptools \
15+
python3-venv \
16+
# libmsi and libgcab are libraries the wixl binary depends on.
17+
libmsi-dev \
18+
libgcab-dev && \
19+
rm -rf /var/lib/apt/lists/* && \
20+
# Install wixl
21+
curl -o /usr/local/bin/wixl -L https://pkg.cloudflare.com/binaries/wixl && \
22+
chmod a+x /usr/local/bin/wixl && \
23+
mkdir -p opt
24+
25+
WORKDIR /opt

.ci/mac.gitlab-ci.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
include:
2+
- local: .ci/commons.gitlab-ci.yml
3+
4+
###############################
5+
### Defaults for Mac Builds ###
6+
###############################
7+
.mac-build-defaults: &mac-build-defaults
8+
rules:
9+
- !reference [.default-rules, run-on-branch]
10+
tags:
11+
- "macstadium-${RUNNER_ARCH}"
12+
parallel:
13+
matrix:
14+
- RUNNER_ARCH: [arm, intel]
15+
cache: {}
16+
17+
######################################
18+
### Build Cloudflared Mac Binaries ###
19+
######################################
20+
build-cloudflared-macos: &build-mac
21+
<<: *mac-build-defaults
22+
stage: build
23+
artifacts:
24+
paths:
25+
- artifacts/*
26+
script:
27+
- '[ "${RUNNER_ARCH}" = "arm" ] && export TARGET_ARCH=arm64'
28+
- '[ "${RUNNER_ARCH}" = "intel" ] && export TARGET_ARCH=amd64'
29+
- ARCH=$(uname -m)
30+
- echo ARCH=$ARCH - TARGET_ARCH=$TARGET_ARCH
31+
- ./.ci/scripts/mac/install-go.sh
32+
- BUILD_SCRIPT=.ci/scripts/mac/build.sh
33+
- if [[ ! -x ${BUILD_SCRIPT} ]] ; then exit ; fi
34+
- set -euo pipefail
35+
- echo "Executing ${BUILD_SCRIPT}"
36+
- exec ${BUILD_SCRIPT}
37+
38+
###############################################
39+
### Build and Sign Cloudflared Mac Binaries ###
40+
###############################################
41+
build-and-sign-cloudflared-macos:
42+
<<: *build-mac
43+
rules:
44+
- !reference [.default-rules, run-on-master]
45+
secrets:
46+
APPLE_DEV_CA_CERT:
47+
vault: gitlab/cloudflare/tun/cloudflared/_branch/master/apple_dev_ca_cert_v2/data@kv
48+
file: false
49+
CFD_CODE_SIGN_CERT:
50+
vault: gitlab/cloudflare/tun/cloudflared/_branch/master/cfd_code_sign_cert_v2/data@kv
51+
file: false
52+
CFD_CODE_SIGN_KEY:
53+
vault: gitlab/cloudflare/tun/cloudflared/_branch/master/cfd_code_sign_key_v2/data@kv
54+
file: false
55+
CFD_CODE_SIGN_PASS:
56+
vault: gitlab/cloudflare/tun/cloudflared/_branch/master/cfd_code_sign_pass_v2/data@kv
57+
file: false
58+
CFD_INSTALLER_CERT:
59+
vault: gitlab/cloudflare/tun/cloudflared/_branch/master/cfd_installer_cert_v2/data@kv
60+
file: false
61+
CFD_INSTALLER_KEY:
62+
vault: gitlab/cloudflare/tun/cloudflared/_branch/master/cfd_installer_key_v2/data@kv
63+
file: false
64+
CFD_INSTALLER_PASS:
65+
vault: gitlab/cloudflare/tun/cloudflared/_branch/master/cfd_installer_pass_v2/data@kv
66+
file: false

.ci/release.gitlab-ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
include:
2+
- local: .ci/commons.gitlab-ci.yml
3+
4+
###########################################
5+
### Push Cloudflared Binaries to Github ###
6+
###########################################
7+
release-cloudflared-to-github:
8+
stage: release
9+
image: $BUILD_IMAGE
10+
extends: .check-tag
11+
needs:
12+
- ci-image-get-image-ref
13+
- package-windows
14+
- build-and-sign-cloudflared-macos
15+
rules:
16+
- !reference [.default-rules, run-on-master]
17+
cache:
18+
paths:
19+
- .cache/pip
20+
variables:
21+
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
22+
KV_NAMESPACE: 380e19aa04314648949b6ad841417ebe
23+
KV_ACCOUNT: 5ab4e9dfbd435d24068829fda0077963
24+
secrets:
25+
KV_API_TOKEN:
26+
vault: gitlab/cloudflare/tun/cloudflared/_dev/cfd_kv_api_token/data@kv
27+
file: false
28+
API_KEY:
29+
vault: gitlab/cloudflare/tun/cloudflared/_dev/cfd_github_api_key/data@kv
30+
file: false
31+
script:
32+
- python3 --version ; pip --version # For debugging
33+
- python3 -m venv venv
34+
- source venv/bin/activate
35+
- pip install pynacl==1.4.0 pygithub==1.55
36+
- echo $VERSION
37+
- echo $TAG_EXISTS
38+
- echo "Running release because tag exists."
39+
- make gitlab-release
File renamed without changes.
File renamed without changes.
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
#!/bin/bash
2+
python3 -m venv env
3+
. env/bin/activate
4+
pip install pynacl==1.4.0 pygithub==1.55
5+
16
VERSION=$(git describe --tags --always --match "[0-9][0-9][0-9][0-9].*.*")
27
echo $VERSION
38

49
export TARGET_OS=windows
510
# This controls the directory the built artifacts go into
6-
export BUILT_ARTIFACT_DIR=built_artifacts/
11+
export BUILT_ARTIFACT_DIR=artifacts/
712
export FINAL_ARTIFACT_DIR=artifacts/
813
mkdir -p $BUILT_ARTIFACT_DIR
914
mkdir -p $FINAL_ARTIFACT_DIR
1015
windowsArchs=("amd64" "386")
1116
for arch in ${windowsArchs[@]}; do
1217
export TARGET_ARCH=$arch
13-
# Copy exe into final directory
18+
# Copy .exe from artifacts directory
1419
cp $BUILT_ARTIFACT_DIR/cloudflared-windows-$arch.exe ./cloudflared.exe
1520
make cloudflared-msi
1621
# Copy msi into final directory
1722
mv cloudflared-$VERSION-$arch.msi $FINAL_ARTIFACT_DIR/cloudflared-windows-$arch.msi
18-
cp $BUILT_ARTIFACT_DIR/cloudflared-windows-$arch.exe $FINAL_ARTIFACT_DIR/cloudflared-windows-$arch.exe
1923
done

.teamcity/windows/builds.ps1 renamed to .ci/scripts/windows/builds.ps1

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,23 @@ Set-StrictMode -Version Latest
22
$ErrorActionPreference = "Stop"
33
$ProgressPreference = "SilentlyContinue"
44

5-
# Relative path to working directory
6-
$CloudflaredDirectory = "go\src\github.com\cloudflare\cloudflared"
5+
$env:TARGET_OS = "windows"
6+
$env:LOCAL_OS = "windows"
77

8-
cd $CloudflaredDirectory
8+
New-Item -Path ".\artifacts" -ItemType Directory
99

1010
Write-Output "Building for amd64"
11-
$env:TARGET_OS = "windows"
12-
$env:CGO_ENABLED = 1
1311
$env:TARGET_ARCH = "amd64"
14-
$env:Path = "$Env:Temp\go\bin;$($env:Path)"
15-
16-
go env
17-
go version
18-
12+
$env:LOCAL_ARCH = "amd64"
13+
$env:CGO_ENABLED = 1
1914
& make cloudflared
2015
if ($LASTEXITCODE -ne 0) { throw "Failed to build cloudflared for amd64" }
21-
copy .\cloudflared.exe .\cloudflared-windows-amd64.exe
16+
copy .\cloudflared.exe .\artifacts\cloudflared-windows-amd64.exe
2217

2318
Write-Output "Building for 386"
24-
$env:CGO_ENABLED = 0
2519
$env:TARGET_ARCH = "386"
26-
make cloudflared
20+
$env:LOCAL_ARCH = "386"
21+
$env:CGO_ENABLED = 0
22+
& make cloudflared
2723
if ($LASTEXITCODE -ne 0) { throw "Failed to build cloudflared for 386" }
28-
copy .\cloudflared.exe .\cloudflared-windows-386.exe
24+
copy .\cloudflared.exe .\artifacts\cloudflared-windows-386.exe

0 commit comments

Comments
 (0)