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

feat(containers): dockerfile and compose API helpers #442

Merged
merged 10 commits into from
Jun 24, 2024
Merged

Conversation

wellwelwel
Copy link
Owner

@wellwelwel wellwelwel commented Jun 23, 2024

A minimal API to assist tests that require containers or tests that run inside containers.

docker

compose

Start containers from a docker-compose.yml in background.

import { docker } from 'poku';

const compose = docker.compose();

// Starts the container(s)
await compose.up();

/**
 * Tests come here 🧪
 */

// Stops the container(s)
await compose.down();

dockerfile

Build and start containers from Dockerfiles in background.

import { docker } from 'poku';

const dockerfile = docker.dockerfile({
  containerName: 'container-name',
  tagName: 'image-name',
});

// Builds the image from the Dockerfile
await dockerfile.build();

// Starts the container
await dockerfile.start();

/**
 * Tests come here 🧪
 */

// Stops and removes both the container and image
await dockerfile.remove();

Starts a container before the entire test suite and stops it on finishing

Poku API (in-code) usage.

import { poku, docker, exit } from 'poku';

const compose = docker.compose({ cwd: './test/docker' });

// Removes the container if it already exists before to start
await compose.down();

// Starts the container
await compose.up();

const result = await poku('./test/integration', {
  noExit: true,
});

await compose.down();

exit(result);
node run.test.mjs

Note

This isn't a complete and robust API designed to create an ORM for Docker, but a minimal API focused on common integration and end-to-end testing needs.

Copy link

codecov bot commented Jun 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.33%. Comparing base (467b462) to head (368dacd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #442      +/-   ##
==========================================
+ Coverage   99.27%   99.33%   +0.05%     
==========================================
  Files          30       32       +2     
  Lines        2916     3155     +239     
  Branches      459      530      +71     
==========================================
+ Hits         2895     3134     +239     
  Misses         20       20              
  Partials        1        1              
Flag Coverage Δ
linux-parallel 99.14% <100.00%> (+0.07%) ⬆️
linux-parallel-options 99.27% <100.00%> (+0.05%) ⬆️
linux-sequential ?
linux-sequential-options ?
osx-parallel 94.70% <41.42%> (-4.37%) ⬇️
osx-parallel-options 94.83% <41.42%> (-4.38%) ⬇️
osx-sequential 93.56% <41.42%> (-4.28%) ⬇️
osx-sequential-options 93.66% <41.42%> (-4.29%) ⬇️
windows-parallel 94.13% <41.42%> (-4.33%) ⬇️
windows-parallel-options 94.26% <41.42%> (-4.34%) ⬇️
windows-sequential ?
windows-sequential-options 93.09% <41.42%> (-4.24%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wellwelwel wellwelwel changed the title feat(container): dockerfile and docker-compose API helpers feat(container): dockerfile and compose API helpers Jun 23, 2024
@wellwelwel wellwelwel changed the title feat(container): dockerfile and compose API helpers feat(containers): dockerfile and compose API helpers Jun 23, 2024
@wellwelwel wellwelwel marked this pull request as ready for review June 23, 2024 22:02
@wellwelwel wellwelwel merged commit ed3d8c6 into main Jun 24, 2024
39 checks passed
@wellwelwel wellwelwel deleted the container branch June 24, 2024 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant