Skip to content

Commit 3909845

Browse files
committed
CI: support building pebble from source.
Shell implementation of get-pebble started getting too unwieldy, so it's been rewritten in Perl.
1 parent 74bd51d commit 3909845

File tree

4 files changed

+186
-64
lines changed

4 files changed

+186
-64
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ jobs:
152152

153153
- name: download pebble
154154
run: |
155-
build/get-pebble.sh
156-
echo TEST_NGINX_PEBBLE_BINARY="$PWD/bin/pebble" >> "$GITHUB_ENV"
155+
TEST_NGINX_PEBBLE_BINARY=$(perl build/get-pebble.pl)
156+
echo TEST_NGINX_PEBBLE_BINARY="$TEST_NGINX_PEBBLE_BINARY" >> "$GITHUB_ENV"
157157
158158
- name: build
159159
id: build

.github/workflows/sanitizers.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ jobs:
7070
key: ${{ runner.os }}-cargo-asan-${{ hashFiles('**/Cargo.lock') }}
7171
restore-keys: ${{ runner.os }}-cargo-asan-
7272

73-
- name: download pebble
73+
- name: download pebble
7474
run: |
75-
build/get-pebble.sh
76-
echo TEST_NGINX_PEBBLE_BINARY="$PWD/bin/pebble" >> "$GITHUB_ENV"
75+
TEST_NGINX_PEBBLE_BINARY=$(perl build/get-pebble.pl)
76+
echo TEST_NGINX_PEBBLE_BINARY="$TEST_NGINX_PEBBLE_BINARY" >> "$GITHUB_ENV"
7777
7878
- name: Configure and build nginx
7979
run: |

build/get-pebble.pl

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
#!/usr/bin/perl
2+
# vim: ts=4 et:
3+
4+
# Copyright (c) F5, Inc.
5+
#
6+
# This source code is licensed under the Apache License, Version 2.0 license
7+
# found in the LICENSE file in the root directory of this source tree.
8+
9+
# Find, download or build letsencrypt/pebble of at least the specified version.
10+
11+
###############################################################################
12+
13+
use strict;
14+
use warnings;
15+
use utf8;
16+
17+
use Cwd qw/ realpath /;
18+
use Digest::SHA;
19+
use File::Copy qw/ copy /;
20+
use File::Path qw/ rmtree /;
21+
use File::Spec;
22+
use File::Temp;
23+
use IPC::Open3;
24+
use POSIX qw/ uname waitpid /;
25+
26+
BEGIN { use FindBin; chdir($FindBin::Bin) }
27+
28+
###############################################################################
29+
30+
my $GO = $ENV{GO} // 'go';
31+
my $NAME = 'pebble';
32+
my $TARGET = File::Spec->join( realpath('..'), 'bin', $NAME );
33+
my $URL = 'https://github.com/letsencrypt/pebble';
34+
my $VERSION = '2.8.0';
35+
36+
my %PREBUILT = (
37+
linux => {
38+
amd64 =>
39+
'34595d915bbc2fc827affb3f58593034824df57e95353b031c8d5185724485ce',
40+
arm64 =>
41+
'0e70f2537353f61cbf06aa54740bf7f7bb5f963ba00e909f23af5f85bc13fd1a',
42+
},
43+
darwin => {
44+
amd64 =>
45+
'9b9625651f8ce47706235179503fec149f8f38bce2b2554efe8c0f2a021f877c',
46+
arm64 =>
47+
'39e07d63dc776521f2ffe0584e5f4f081c984ac02742c882b430891d89f0c866',
48+
},
49+
);
50+
51+
my %ARCH = (
52+
aarch64 => 'arm64',
53+
x86_64 => 'amd64',
54+
);
55+
56+
###############################################################################
57+
58+
my ( $bin, $version ) = do_check();
59+
if ( defined $version ) {
60+
print STDERR "found pebble $version at $bin\n";
61+
print $bin;
62+
exit 0;
63+
}
64+
65+
my $arch = ( uname() )[4];
66+
$arch = $ARCH{$arch} if defined $ARCH{$arch};
67+
68+
my $tempdir = File::Temp->newdir( 'get-pebble-XXXXXXXXXX', TMPDIR => 1 )
69+
or die "Can't create temp directory: $!\n";
70+
71+
if ( my $hash = $PREBUILT{$^O}{$arch} ) {
72+
print STDERR "downloading pebble $VERSION for $^O $arch\n";
73+
print do_download( $^O, $arch, $hash );
74+
}
75+
else {
76+
print STDERR "building pebble $VERSION\n";
77+
print do_compile();
78+
}
79+
80+
###############################################################################
81+
82+
sub do_check {
83+
my @names = which($NAME);
84+
unshift @names, $TARGET;
85+
86+
BIN: foreach my $bin (@names) {
87+
my $version;
88+
$version = $1
89+
if qx{ $bin -version 2>/dev/null } =~ /version:\s+v?(\d[\d\.]+)/;
90+
next unless $version;
91+
92+
my @v = split /\./, $version;
93+
foreach my $n ( split /\./, $VERSION ) {
94+
my $v = shift @v || 0;
95+
last if $v > $n;
96+
next BIN if $v < $n;
97+
}
98+
99+
return ( $bin, $version );
100+
}
101+
}
102+
103+
sub do_compile {
104+
my @GO = which($GO) or die "Can't find Go toolchain: $!\n";
105+
106+
my $repo = $ENV{PEBBLE_SOURCE_DIR}
107+
// File::Spec->join( $tempdir, 'pebble' );
108+
109+
run( 'git', 'clone', '--depth=1', '-b', "v${VERSION}", $URL, $repo )
110+
unless -d File::Spec->join( $repo, '.git' );
111+
112+
chdir($repo) or die "chdir failed: $!\n";
113+
114+
run( 'git', 'fetch', '--depth=1', 'origin', 'tag', "v${VERSION}" );
115+
run( 'git', 'checkout', "v${VERSION}" );
116+
117+
my $commit = run( 'git', 'rev-parse', 'HEAD' );
118+
my $ldflags = "-X 'main.version=v${VERSION} ($commit)'";
119+
120+
run( $GO[0], 'build', '-ldflags=' . $ldflags, './cmd/pebble' );
121+
122+
chdir($FindBin::Bin);
123+
return copy_binary( File::Spec->join( $repo, 'pebble' ) );
124+
}
125+
126+
sub do_download {
127+
my ( $os, $arch, $hash ) = @_;
128+
129+
chdir($tempdir) or die "chdir failed: $!\n";
130+
131+
my $archive = "pebble-$os-$arch.tar.gz";
132+
run( 'curl', '--fail', '--silent', '-L', '-o', $archive,
133+
"$URL/releases/download/v${VERSION}/${archive}" );
134+
die "Checksum verification failed\n" if sha256sum($archive) ne $hash;
135+
136+
run( 'tar', 'xzf', $archive );
137+
138+
chdir($FindBin::Bin);
139+
return copy_binary(
140+
File::Spec->join( $tempdir, "pebble-$os-$arch", $os, $arch, 'pebble' )
141+
);
142+
}
143+
144+
sub copy_binary {
145+
my ($src) = @_;
146+
mkdir dirname($TARGET);
147+
copy $src, $TARGET or die "copy $src, $TARGET: $!\n";
148+
chmod 0755, $TARGET or die "chown $TARGET: $!\n";
149+
return $TARGET;
150+
}
151+
152+
sub dirname {
153+
my ($filename) = @_;
154+
my ( $vol, $dir ) = File::Spec->splitpath($filename);
155+
return File::Spec->catpath( $vol, $dir, '' );
156+
}
157+
158+
sub run {
159+
my $pid = open3( undef, my $fh, '>&STDERR', @_ );
160+
waitpid( $pid, 0 );
161+
die "$_[0] failed: $! $?\n" unless $? == 0;
162+
163+
$fh->read( my $out, 32768 );
164+
chomp($out);
165+
return $out;
166+
}
167+
168+
sub sha256sum {
169+
my ($filename) = @_;
170+
my $sha = Digest::SHA->new('SHA-256');
171+
$sha->addfile( $filename, 'b' );
172+
return lc( $sha->hexdigest() );
173+
}
174+
175+
sub which {
176+
my ($name) = @_;
177+
my @paths = File::Spec->path();
178+
return grep { -x } map { File::Spec->join( $_, $name ) } @paths;
179+
}
180+
181+
###############################################################################

build/get-pebble.sh

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)