Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflows: DevEx improvements #173

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ARG VARIANT=5-bookworm
FROM perl:${VARIANT}

COPY cpanfile /tmp/cpanfile
RUN cpm install -g --with-develop --cpanfile /tmp/cpanfile \
&& rm -rf /root/.perl-cpm /tmp/cpanfile
34 changes: 34 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"build": {
"dockerfile": "./Dockerfile",
"context": ".."
},
"containerEnv": {
"DOCKER_PERL_DOWNLOADS_DIR": "/tmp/docker-perl-downloads"
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"configureZshAsDefaultShell": "true"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/dhoeric/features/act:1": {}
},
"customizations": {
"vscode": {
"settings": {
"files.associations": {
"cpanfile": "cpanfile"
}
},
"extensions": [
"bscan.perlnavigator",
"bayashi.perlcpanfile",
"stkb.rewrap",
"GitHub.vscode-pull-request-github",
"GitHub.vscode-github-actions"
]
}
},
"remoteUser": "vscode"
}
37 changes: 19 additions & 18 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name: Build and Test

on:
push:
branches:
- '**'
tags-ignore:
- '*'
pull_request:
paths:
- '**/Dockerfile'
- '!.devcontainer/Dockerfile'
- '**/DevelPatchPerl.patch'

defaults:
run:
Expand All @@ -18,46 +17,56 @@ jobs:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate.outputs.matrix }}

steps:
- uses: actions/checkout@master
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- id: generate
name: Enumerate Dockerfiles
run: |
matrix="$(dirname */Dockerfile | sort -rn | jq -csR 'rtrimstr("\n") | split("\n") | { directory: . }')"
echo "matrix=$matrix" >> $GITHUB_OUTPUT

build-image:
needs: generate-matrix
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
name: ${{ matrix.directory }}

steps:
- uses: actions/checkout@master
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Clone docker-library/official-images (for testing)
run: |
git clone --depth 1 --single-branch https://github.com/docker-library/official-images.git

- name: Build image
run: |
docker version
dir='${{ matrix.directory }}'
img="perl:${dir//,/-}"
docker build -t "$img" "$dir"
docker buildx build --progress=plain -t "$img" "$dir"

- name: Inspect image creation and tag time
run: |
dir='${{ matrix.directory }}'
img="perl:${dir//,/-}"
docker image inspect --format '{{.Created}}' "$img"
docker image inspect --format '{{.Metadata.LastTagTime}}' "$img"

- name: Run tests from docker-library/official-images
run: |
dir='${{ matrix.directory }}'
img="perl:${dir//,/-}"
./official-images/test/run.sh "$img"

- name: Run HTTPS access test
run: |
dir='${{ matrix.directory }}'
img="perl:${dir//,/-}"
docker run "$img" perl -MHTTP::Tiny -E 'if (HTTP::Tiny->new->get("https://github.com")->{status} == 200) { exit 0 } exit 1'

- name: Run cpanm install test
run: |
dir='${{ matrix.directory }}'
Expand All @@ -67,13 +76,15 @@ jobs:
docker run "$img" cpanm -v Net::[email protected]_02
fi
docker run "$img" cpanm -v Mojolicious

- name: Run cpanm no-lwp by default test
run: |
dir='${{ matrix.directory }}'
img="perl:${dir//,/-}"
if [[ "$dir" != *"slim"* ]]; then
docker run "$img" bash -c "cpanm -v -n LWP && cpanm -v -n local::lib"
fi

- name: Run cpm install test
run: |
dir='${{ matrix.directory }}'
Expand All @@ -83,13 +94,3 @@ jobs:
docker run "$img" cpm install -v Net::[email protected]_02
fi
docker run "$img" cpm install -v Mojolicious
- name: COPY all to default WORKDIR
run: |
dir='${{ matrix.directory }}'
img="perl:${dir//,/-}"
mkdir -p test/lib
cat <<EOF >Dockerfile
FROM $img
COPY . .
EOF
docker build -f Dockerfile test
42 changes: 32 additions & 10 deletions .github/workflows/generate-dockerfiles-patches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,54 @@ name: Generate Dockerfiles/patches
on:
push:
branches:
- '**'
- master
tags-ignore:
- '*'
pull_request:
paths:
- cpanfile
- config.yml
- generate.pl
- .github/workflows/generate-dockerfiles-patches.yml

jobs:
generate:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Set up git user name and email
run: |
git config --global user.email "test@github-actions"
git config --global user.name "GitHub Actions"
- uses: actions/checkout@master

- name: Install system perl and cpanm
run: |
sudo apt-get install --no-install-recommends -y perl cpanminus
sudo apt-get update && sudo apt-get install -y --no-install-recommends perl cpanminus

- name: Install dependencies
run: |
cpanm --quiet --installdeps --notest -L local .
sudo cpanm --quiet --installdeps --notest .

- name: Generate Dockerfiles/patches
id: generate
run: |
perl -Ilocal/lib/perl5 ./generate.pl
- name: Show diffstat (if any)
run: |
git --no-pager diff --stat HEAD
- name: Show diffstat (if any)
export DOCKER_PERL_DOWNLOADS_DIR=/tmp/docker-perl-downloads
perl ./generate.pl
/usr/bin/git --no-pager diff --stat > diffstat.txt
if [[ -s diffstat.txt ]]; then
echo has_extra_diffs=1 >> $GITHUB_OUTPUT
fi

- name: Fail if there are extra diffs
if: steps.generate.outputs.has_extra_diffs
run: |
git --no-pager diff --stat HEAD
echo "::error title=generate::Extra diffs found during generate"
echo "Additional changes found during generate - check diffstat below:"
echo "::group::diffstat"
cat diffstat.txt
echo "::endgroup::"
echo

exit 1
15 changes: 8 additions & 7 deletions generate.pl
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ sub die_with_sample {
die_with_sample unless defined $config->{releases};
die_with_sample unless ref $config->{releases} eq "ARRAY";

if (!-d "downloads") {
mkdir "downloads" or die "Couldn't create a downloads directory";
my $downloads = $ENV{DOCKER_PERL_DOWNLOADS_DIR} // "downloads";
if (!-d "$downloads") {
mkdir "$downloads" or die "Couldn't create a downloads directory at $downloads";
}

for my $build (@{$config->{builds}}) {
Expand All @@ -141,21 +142,21 @@ sub die_with_sample {
my $tarball = CPAN::Perl::Releases::MetaCPAN::perl_tarballs($release->{version})->{'tar.gz'};
my ($file) = File::Basename::fileparse($tarball);
my $url = "https://cpan.metacpan.org/authors/id/$tarball";
if (-f "downloads/$file" && `sha256sum downloads/$file` =~ /^\Q$release->{sha256}\E\s+\Qdownloads\/$file\E/) {
if (-f "$downloads/$file" && `sha256sum $downloads/$file` =~ /^\Q$release->{sha256}\E\s+\Q$downloads\/$file\E/) {
print "Skipping download of $file, already current\n";
}
else {
print "Downloading $url\n";
getstore($url, "downloads/$file");
getstore($url, "$downloads/$file");
}
{
my $dir = "downloads/perl-$release->{version}";
my $dir = "$downloads/perl-$release->{version}";
qx{rm -fR $dir};
mkdir $dir or die "Couldn't create $dir";
qx{
tar -C "downloads" -xf $dir.tar.gz &&\
tar -C "$downloads" -xf $dir.tar.gz &&\
cd $dir &&\
find . -exec chmod u+w {} + &&\
chown -R \$(id -u):\$(id -g) . &&\
git init &&\
git add . &&\
git commit -m tmp
Expand Down
Loading