Skip to content

Draft: Added setup test #74

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

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7df5cd8
Test data - added test data
mickeyn May 3, 2025
9256cd9
author - fix script
mickeyn May 6, 2025
3f1e1fa
backpan - fix script
mickeyn May 6, 2025
7364503
backup - fix script
mickeyn May 6, 2025
d335e49
check - fix script
mickeyn May 6, 2025
2024cb7
checksum - fix script
mickeyn May 6, 2025
8bfc512
contributor - fix script
mickeyn May 6, 2025
176b28e
cover - fix script
mickeyn May 6, 2025
a76473e
cpan_testers - fix script
mickeyn May 6, 2025
8f04dcd
cpan_testers_api - fix script
mickeyn May 6, 2025
47ba547
cve - fix script
mickeyn May 6, 2025
89e23f7
external - fix script
mickeyn May 6, 2025
78e2ccc
favorite - fix script
mickeyn May 6, 2025
9d95b5f
first - fix script
mickeyn May 6, 2025
9ec9923
latest - fix script
mickeyn May 6, 2025
e0fa317
mirrors - fix script
mickeyn May 6, 2025
f48435d
package - fix script
mickeyn May 6, 2025
fbfd09e
permission - fix script
mickeyn May 6, 2025
46c4630
purge - fix script
mickeyn May 6, 2025
b374eaf
release - fix script
mickeyn May 6, 2025
e95fba6
river - fix script
mickeyn May 6, 2025
87b40ee
session - fix script
mickeyn May 6, 2025
a011f78
snapshot - fix script
mickeyn May 6, 2025
406ef2b
suggest - fix script
mickeyn May 6, 2025
8733aa3
tickets - fix script
mickeyn May 6, 2025
280d49d
watcher - fix script
mickeyn May 6, 2025
5594c0b
Added mapper logic - create full index + mapping
mickeyn May 6, 2025
5cb6cbe
ES - support dev mode
mickeyn May 6, 2025
dceb9eb
a few more type removals and wrong node setting
mickeyn May 7, 2025
abb96cb
setup test - draft
mickeyn May 6, 2025
4566b76
added ci config
mickeyn May 9, 2025
7c5fd58
test
mickeyn May 9, 2025
eabc9f7
bring up the elasticsearch_test service
mickeyn May 10, 2025
54e3174
tidy
mickeyn May 11, 2025
4e27003
docker test run command
mickeyn May 11, 2025
e57c72d
Add docker-compose.yml
oalders May 14, 2025
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
80 changes: 80 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
# Use the latest 2.1 version of CircleCI pipeline process engine. See:
# https://circleci.com/docs/2.0/configuration-reference
version: 2.1
orbs:
codecov: codecov/codecov@4.1.0
# Orchestrate or schedule a set of jobs
workflows:
docker-compose:
jobs:
- build-and-test
jobs:
build-and-test:
machine: true
resource_class: large
steps:
- run:
name: docker-compose version
command: docker-compose --version
- run:
command: |
git clone https://github.com/metacpan/metacpan-docker.git
cd metacpan-docker
name: metacpan-docker checkout
- checkout:
path: metacpan-docker/src/metacpan-ingest
- run:
command: |
pushd metacpan-docker
./bin/metacpan-docker init
name: clone missing repositories
- run:
command: |
pushd metacpan-docker
docker-compose build --build-arg CPM_ARGS='--with-test' insgest_test
name: compose build
- run:
command: |
pushd metacpan-docker
./bin/metacpan-docker init
#docker-compose --verbose up -d ingest_test
docker-compose --profile ingest-test up --build
name: compose up
- run:
command: |
pushd metacpan-docker
docker-compose exec -T ingest_test cpm install -g Devel::Cover
name: install Devel::Cover
# Since we're running docker-compose -d, we don't actually know if
# Elasticsearch is available at the time this build step begins. We
# probably need to wait for it here, so we'll add our own check.
- run:
command: |
pushd metacpan-docker
./src/metacpan-ingest/wait-for-es.sh http://localhost:9200 elasticsearch_test
name: wait for ES
- run:
command: |
pushd metacpan-docker
docker build . -t metacpan/metacpan-ingest && docker compose run ingest env PLACK_ENV=dev HARNESS_PERL_SWITCHES="-MDevel::Cover=+ignore,^t/|^test-data/|^etc/" prove -lrv --jobs 4 t
# docker-compose exec -T ingest_test env PLACK_ENV=dev HARNESS_PERL_SWITCHES="-MDevel::Cover=+ignore,^t/|^test-data/|^etc/" prove -lr --jobs 4 t
name: run tests with coverage
# We are relying on environment variables from the host to be available when
# we publish the report, so we publish from the host rather than trying
# to propagate env variables to the container.
- run:
command: |
pushd metacpan-docker
docker-compose exec -T ingest_test cover -report json
name: create coverage report
- codecov/upload:
file: metacpan-docker/src/metacpan-ingest/cover_db/cover.json
- run:
command: |
pushd metacpan-docker
docker-compose logs
docker stats --no-stream
docker ps -a | head
name: docker-compose logs
when: on_fail
2 changes: 1 addition & 1 deletion .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run Perl tests
run: docker run -i ${{ steps.docker-build-test.outputs.imageid }}
run: docker compose build && docker compose run ingest env PLACK_ENV=dev prove -lv t
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ COPY lib lib
COPY conf conf
COPY *.conf .

# move the following to test only
COPY t t
COPY test_data test_data

ENV PERL5LIB="/app/local/lib/perl5:/app/lib" PATH="/app/local/bin:${PATH}"

USER metacpan
Expand Down
7 changes: 3 additions & 4 deletions bin/author.pl
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,17 @@
};

# args
my ( $mode, $pauseid, $whois_file );
my ( $pauseid, $whois_file );
GetOptions(
"mode=s" => \$mode,
"pauseid=s" => \$pauseid,
"whois_file=s" => \$whois_file,
);

# setup
my $es = MetaCPAN::ES->new( index => "author", ( $mode ? ( mode => $mode ) : () ) );
my $es = MetaCPAN::ES->new( index => "author" );

log_info {'Reading 00whois'};
my $authors_data = read_00whois( $whois_file );
my $authors_data = read_00whois($whois_file);

if ($pauseid) {
log_info {"Indexing 1 author"};
Expand Down
8 changes: 4 additions & 4 deletions bin/backpan.pl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

# setup
my $cpan_file_map = cpan_file_map();
my $es_release = MetaCPAN::ES->new( type => "release" );
my $es_file = MetaCPAN::ES->new( type => "file" );
my $es_release = MetaCPAN::ES->new( index => "release" );
my $es_file = MetaCPAN::ES->new( index => "file" );

my %bulk;
my %release_status;
Expand Down Expand Up @@ -55,7 +55,7 @@ ()
(
$undo
or exists $cpan_file_map->{$author}{$archive}
)
)
? 'cpan'
: 'backpan',
$release->{_id}
Expand Down Expand Up @@ -169,6 +169,6 @@ =head1 DESCRIPTION
Sets "backpan" status on all BackPAN releases.

--undo will set distributions' status back as 'cpan'
--file_only will only fix the 'file' type
--file_only will only fix the 'file' index

=cut
15 changes: 5 additions & 10 deletions bin/backup.pl
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@
my $size = 1000;
my $index = "cpan";

my ( $dry_run, $mode, $purge, $restore );
my ( $dry_run, $purge, $restore );
GetOptions(
"batch_size=i" => \$batch_size,
"dry_run" => \$dry_run,
"index=s" => \$index,
"mode=s" => \$mode,
"purge" => \$purge,
"restore=s" => \$restore,
"size=i" => \$size,
);
# TODO: find a better way
my @es_mode = ( $mode ? mode => $mode : () );
$mode eq 'test' and Log::Log4perl::init('log4perl_test.conf');

# setup
my $home = home();
Expand Down Expand Up @@ -76,7 +72,7 @@ ()
# create a new bulk helper for each
my $key = $raw->{_index};

$es_store{$key} ||= MetaCPAN::ES->new( index => $key, @es_mode );
$es_store{$key} ||= MetaCPAN::ES->new( index => $key );
my $es = $es_store{$key};

$bulk_store{$key} ||= $es->bulk( max_count => $batch_size );
Expand Down Expand Up @@ -156,15 +152,14 @@ ()
}

sub run_backup {
my $filename = join( '-',
DateTime->now->strftime('%F'),
grep {defined} $index );
my $filename
= join( '-', DateTime->now->strftime('%F'), grep {defined} $index );

my $file = $home->child( qw< var backup >, "$filename.json.gz" );
$file->parent->mkpath unless ( -e $file->parent );
my $fh = IO::Zlib->new( "$file", 'wb4' );

my $es = MetaCPAN::ES->new( index => $index, @es_mode );
my $es = MetaCPAN::ES->new( index => $index );
my $scroll = $es->scroll(
scroll => '1m',
body => {
Expand Down
11 changes: 5 additions & 6 deletions bin/check.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
use MetaCPAN::Ingest qw< read_02packages_fh >;

# args
my ( $module, $max_errors, $errors_only );

my ( $errors_only, $max_errors, $module );
GetOptions(
"module=s" => \$module,
"max_errors" => \$max_errors,
"errors_only" => \$errors_only,
"max_errors" => \$max_errors,
"module=s" => \$module,
);

# setup
my $error_count = 0;
my $packages_fh = read_02packages_fh();
my $es_file = MetaCPAN::ES->new( type => "file" );
my $es_release = MetaCPAN::ES->new( type => "release" );
my $es_file = MetaCPAN::ES->new( index => "file" );
my $es_release = MetaCPAN::ES->new( index => "release" );

my $modules_start = 0;
while ( my $line = <$packages_fh> ) {
Expand Down
6 changes: 3 additions & 3 deletions bin/checksum.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

# args
my $limit = 1000;
my $dry_run;
my ($dry_run);
GetOptions(
"limit=i" => \$limit,
"dry_run" => \$dry_run,
"limit=i" => \$limit,
);

# setup
my $es = MetaCPAN::ES->new( type => "release" );
my $es = MetaCPAN::ES->new( index => "release" );
my $bulk;
$bulk = $es->bulk() unless $dry_run;

Expand Down
9 changes: 4 additions & 5 deletions bin/contributor.pl
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
"all" => \$all,
"distribution=s" => \$distribution,
"release=s" => \$release,

);

# setup
my $author_mapping = {};
my $email_mapping = {};

my $es_author = MetaCPAN::ES->new( type => 'author' );
my $es_release = MetaCPAN::ES->new( type => "release" );
my $es_contributor = MetaCPAN::ES->new( type => "contributor" );
my $es_author = MetaCPAN::ES->new( index => 'author' );
my $es_release = MetaCPAN::ES->new( index => "release" );
my $es_contributor = MetaCPAN::ES->new( index => "contributor" );

run();

Expand Down Expand Up @@ -296,6 +295,6 @@ =head1 SYNOPSIS
=head1 DESCRIPTION

Update the list of contributors (CPAN authors only) of all/matching
releases in the 'contributor' type (index).
releases in the 'contributor' index.

=cut
19 changes: 9 additions & 10 deletions bin/cover.pl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
my ( $json_file, $test );
GetOptions(
"json=s" => \$json_file,
"test" => \$test
"test" => \$test,
);
my $cover_url //= 'http://cpancover.com/latest/cpancover.json';
my $cover_dev_url //= 'http://cpancover.com/latest/cpancover_dev.json';
Expand All @@ -24,8 +24,9 @@
my %valid_keys
= map { $_ => 1 } qw< branch condition statement subroutine total >;

my $es = MetaCPAN::ES->new( index => "cover", type => "cover" );
my $bulk = $es->bulk();
my $es_release = MetaCPAN::ES->new( index => "release" );
my $es_cover = MetaCPAN::ES->new( index => "cover" );
my $bulk_cover = $es_cover->bulk();

my $data = retrieve_cover_data();

Expand All @@ -34,11 +35,9 @@
for my $dist ( sort keys %{$data} ) {
for my $version ( keys %{ $data->{$dist} } ) {
my $release = $dist . '-' . $version;
my $rel_check = $es->search(
index => 'cpan',
type => 'release',
size => 0,
body => {
my $rel_check = $es_release->search(
size => 0,
body => {
query => { term => { name => $release } },
},
);
Expand All @@ -56,7 +55,7 @@
delete $doc_data{$k} unless exists $valid_keys{$k};
}

$bulk->update( {
$bulk_cover->update( {
id => $release,
doc => {
distribution => $dist,
Expand All @@ -69,7 +68,7 @@
}
}

$bulk->flush;
$bulk_cover->flush;

###

Expand Down
2 changes: 1 addition & 1 deletion bin/cpan_testers.pl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

my $ua = ua();

my $es = MetaCPAN::ES->new( type => "release" );
my $es = MetaCPAN::ES->new( index => "release" );
my $bulk = $es->bulk();

log_info { 'Mirroring ' . $db };
Expand Down
7 changes: 1 addition & 6 deletions bin/cpan_testers_api.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use v5.36;

use Cpanel::JSON::XS qw< decode_json >;
use Getopt::Long;

use MetaCPAN::Logger qw< :log :dlog >;

Expand All @@ -13,10 +12,6 @@
ua
>;

# args
my ();
GetOptions();

# setup
my $home = home();

Expand All @@ -27,7 +22,7 @@

my $ua = ua();

my $es = MetaCPAN::ES->new( type => "release" );
my $es = MetaCPAN::ES->new( index => "release" );
my $bulk = $es->bulk();

log_info { 'Fetching ' . $url };
Expand Down
Loading
Loading