|
| 1 | +#!/usr/bin/env perl |
| 2 | +use v5.20; |
| 3 | +use strict; |
| 4 | +use warnings; |
| 5 | +use YAML::XS; |
| 6 | + |
| 7 | +sub die_with_sample { |
| 8 | + die <<EOF; |
| 9 | +
|
| 10 | +The Releases.yaml file must look roughly like: |
| 11 | +
|
| 12 | +releases: |
| 13 | + - version: 5.20.0 |
| 14 | + sha1: asdasdadas |
| 15 | + pause: RJBS |
| 16 | +
|
| 17 | +Where version is the version number of Perl, sha1 is the SHA1 of the |
| 18 | +tar.bz2 file, and pause is the PAUSE account of the release manager. |
| 19 | +
|
| 20 | +If needed or desired, extra_flags: can be added, which will be passed |
| 21 | +verbatim to Configure. |
| 22 | +
|
| 23 | +EOF |
| 24 | +} |
| 25 | + |
| 26 | +my $yaml = do { |
| 27 | + open my $fh, "Releases.yaml" or die "Couldn't open releases"; |
| 28 | + local $/; |
| 29 | + Load <$fh>; |
| 30 | +}; |
| 31 | + |
| 32 | +my $template = do { |
| 33 | + local $/; |
| 34 | + <DATA>; |
| 35 | +}; |
| 36 | + |
| 37 | +my %builds = ( |
| 38 | + "64bit" => "-Duse64bitall", |
| 39 | + "64bit,threaded" => "-Dusethreads -Duse64bitall", |
| 40 | +); |
| 41 | + |
| 42 | +die_with_sample unless defined $yaml->{releases}; |
| 43 | +die_with_sample unless ref $yaml->{releases} eq "ARRAY"; |
| 44 | + |
| 45 | +for my $release (@{$yaml->{releases}}) { |
| 46 | + do { die_with_sample unless $release->{$_}} for (qw(version pause sha1)); |
| 47 | + $release->{pause} =~ s#(((.).).*)#$3/$2/$1#; |
| 48 | + $release->{extra_flags} = "" unless defined $release->{extra_flags}; |
| 49 | + |
| 50 | + for my $config (keys %builds) { |
| 51 | + my $output = $template; |
| 52 | + $output =~ s/{{$_}}/$release->{$_}/mg for (qw(version pause extra_flags)); |
| 53 | + $output =~ s/{{args}}/$builds{$config}/mg; |
| 54 | + |
| 55 | + my $dir = sprintf "%i.%03i.%03i-%s", |
| 56 | + ($release->{version} =~ /(\d+)\.(\d+)\.(\d+)/), |
| 57 | + $config; |
| 58 | + |
| 59 | + open my $sha1, ">$dir/sha1.txt" or die "Couldn't open $dir/sha1.txt for writing"; |
| 60 | + print $sha1 "$release->{sha1} perl-$release->{version}.tar.bz2\n"; |
| 61 | + close $sha1; |
| 62 | + |
| 63 | + open my $dockerfile, ">$dir/Dockerfile" or die "Couldn't open $dir/Dockerfile for writing"; |
| 64 | + print $dockerfile $output; |
| 65 | + close $dockerfile; |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +=pod |
| 70 | +
|
| 71 | +=head1 NAME |
| 72 | +
|
| 73 | +generate.pl |
| 74 | +
|
| 75 | +=head1 SYNOPSIS |
| 76 | +
|
| 77 | +generate.pl is a little helper script to reinitalize the Dockerfiles from a YAML file. |
| 78 | +
|
| 79 | +=head1 DESCRIPTION |
| 80 | +
|
| 81 | +generate.pl is meant to be run from the actual repo directory, with a Releases.yaml file |
| 82 | +correctly configured. It starts with a 'releases' key, which contains a list of releases, |
| 83 | +each with the following keys: |
| 84 | +
|
| 85 | +=over 4 |
| 86 | +
|
| 87 | +=item version |
| 88 | +
|
| 89 | +The actual perl version, such as B<5.20.1>. |
| 90 | +
|
| 91 | +=item sha1 |
| 92 | +
|
| 93 | +The SHA-1 of the C<.tar.bz2> file for that release. |
| 94 | +
|
| 95 | +=item pause |
| 96 | +
|
| 97 | +The PAUSE (CPAN user) account that the release was uploaded to. |
| 98 | +
|
| 99 | +=item (optionally) extra_args |
| 100 | +
|
| 101 | +Additional text to pass to C<Configure>. At the moment, this is necessary for |
| 102 | +5.18.x so that it can get the C<-fwrapv> flag. |
| 103 | +
|
| 104 | +=back |
| 105 | +
|
| 106 | +=cut |
| 107 | + |
| 108 | +__DATA__ |
| 109 | +FROM buildpack-deps |
| 110 | +MAINTAINER Peter Martini <[email protected]> |
| 111 | +
|
| 112 | +RUN apt-get update && apt-get install -y curl procps |
| 113 | +
|
| 114 | +RUN mkdir /usr/src/perl |
| 115 | +WORKDIR /usr/src/perl |
| 116 | +
|
| 117 | +COPY sha1.txt /tmp/sha1.txt |
| 118 | +RUN curl -SL https://cpan.metacpan.org/authors/id/{{pause}}/perl-{{version}}.tar.bz2 -o perl-{{version}}.tar.bz2 \ |
| 119 | + && sha1sum -c /tmp/sha1.txt \ |
| 120 | + && tar --strip-components=1 -xjf perl-{{version}}.tar.bz2 -C /usr/src/perl \ |
| 121 | + && rm perl-{{version}}.tar.bz2 /tmp/sha1.txt |
| 122 | +
|
| 123 | +RUN ./Configure {{args}} {{extra_flags}} -des \ |
| 124 | + && make -j$(nproc) \ |
| 125 | + && TEST_JOBS=$(nproc) make test_harness \ |
| 126 | + && make install \ |
| 127 | + && make veryclean |
| 128 | +
|
| 129 | +WORKDIR /usr/src |
| 130 | +RUN curl -LO https://raw.githubusercontent.com/miyagawa/cpanminus/master/cpanm \ |
| 131 | + && chmod +x cpanm \ |
| 132 | + && ./cpanm App::cpanminus \ |
| 133 | + && rm ./cpanm |
| 134 | +
|
| 135 | +WORKDIR /root |
| 136 | +
|
| 137 | +CMD ["perl{{version}}","-de0"] |
0 commit comments