-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(containers): dockerfile and compose API helpers (#442)
* feat(container): dockerfile and docker-compose API helpers * ci: debug * ci: debug * ci: debug * ci: debug * ci: disable container tests for Windows * ci: disable container tests for Windows * chore: include detach option * chore: remove old helper * docs: improve documentation
- Loading branch information
1 parent
467b462
commit ed3d8c6
Showing
69 changed files
with
1,816 additions
and
1,011 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM node:lts-alpine | ||
|
||
WORKDIR /usr/app | ||
|
||
COPY src/dockerfile-server.js /usr/app/server.js | ||
|
||
CMD ["node", "server.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM node:lts-alpine | ||
|
||
WORKDIR /usr/app | ||
|
||
COPY src/docker-compose-server.js /usr/app/server.js | ||
|
||
CMD ["node", "server.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: '3.9' | ||
services: | ||
server: | ||
container_name: poku-test-docker-compose-server | ||
build: | ||
context: . | ||
dockerfile: compose.Dockerfile | ||
ports: | ||
- '127.0.0.1:6001:6001' | ||
environment: | ||
NODE_ENV: production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const http = require('node:http'); | ||
|
||
const server = http.createServer((_, res) => { | ||
res.statusCode = 200; | ||
res.setHeader('Content-Type', 'text/plain'); | ||
res.end('Hello, World!\n'); | ||
}); | ||
|
||
server.listen(6001); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const http = require('node:http'); | ||
|
||
const server = http.createServer((_, res) => { | ||
res.statusCode = 200; | ||
res.setHeader('Content-Type', 'text/plain'); | ||
res.end('Hello, World!\n'); | ||
}); | ||
|
||
server.listen(6000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
export type DockerfileConfigs = { | ||
/** | ||
* Specifies the imange name | ||
* | ||
* E.g., `"name"`, `"name:tag"`. | ||
*/ | ||
tagName: string; | ||
|
||
/** | ||
* Specifies the container name. | ||
*/ | ||
containerName: string; | ||
|
||
/** | ||
* Specifies the **Dockerfile** path | ||
* | ||
* --- | ||
* | ||
* @default "./Dockerfile" | ||
*/ | ||
file?: string; | ||
|
||
/** | ||
* Specifies the context path of the Dockerfile | ||
* | ||
* - It's different from `cwd`. | ||
* | ||
* --- | ||
* | ||
* @default "." | ||
*/ | ||
context?: string; | ||
|
||
/** | ||
* Specifies the ports to expose. | ||
* | ||
* E.g., `"6000:6000"`, `"8080:80"`, `"127.0.0.1:3306:3306"`. | ||
*/ | ||
ports?: string[]; | ||
|
||
/** | ||
* Specifies the container environments variables. | ||
* | ||
* E.g, `"VAR1"`, `"VAR1=value1"` | ||
*/ | ||
environments?: string[]; | ||
|
||
/** | ||
* Specifies a `.env` path to **Dockerfile**. | ||
*/ | ||
envFile?: string; | ||
|
||
/** | ||
* Forces the image build without cache. | ||
*/ | ||
cache?: boolean; | ||
|
||
/** | ||
* Doesn't run the container in the background and returns the container's process exit result (boolean). | ||
* | ||
* - Set to `false` to test whether a container was executed and finished successfully. | ||
* | ||
* --- | ||
* | ||
* @default true | ||
*/ | ||
detach?: boolean; | ||
|
||
/** | ||
* Defines the root directory where the process will run. | ||
* | ||
* --- | ||
* | ||
* @default "." | ||
*/ | ||
cwd?: string; | ||
|
||
/** | ||
* Show logs from **Docker** in real time. | ||
*/ | ||
verbose?: boolean; | ||
}; | ||
|
||
export type DockerComposeConfigs = { | ||
/** | ||
* Specifies the **docker-compose.yml** path | ||
* | ||
* --- | ||
* | ||
* @default "./docker-compose.yml" | ||
*/ | ||
file?: string; | ||
|
||
/** | ||
* Specifies the project name. | ||
*/ | ||
projectName?: string; | ||
|
||
/** | ||
* Specifies a `.env` path to **docker-compose.yml**. | ||
*/ | ||
envFile?: string; | ||
|
||
/** | ||
* Defines the root directory where the process will run. | ||
* | ||
* --- | ||
* | ||
* @default "." | ||
*/ | ||
cwd?: string; | ||
|
||
/** | ||
* Forces the images (**Dockerfile**) to be rebuilt. | ||
*/ | ||
build?: boolean; | ||
|
||
/** | ||
* Starts only a specific **docker-compose.yml** service. | ||
*/ | ||
serviceName?: string; | ||
|
||
/** | ||
* Doesn't run the container in the background and returns the container's process exit result (boolean). | ||
* | ||
* - Set to `false` to test whether a container was executed and finished successfully. | ||
* | ||
* --- | ||
* | ||
* @default true | ||
*/ | ||
detach?: boolean; | ||
|
||
/** | ||
* Show logs from **Docker** in real time. | ||
*/ | ||
verbose?: boolean; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* c8 ignore next */ | ||
import { | ||
DockerComposeConfigs, | ||
DockerfileConfigs, | ||
} from '../@types/container.js'; | ||
import { DockerCompose, DockerContainer } from '../services/container.js'; | ||
|
||
/** | ||
* | ||
* A minimal API to assist tests that require containers or tests that run inside containers using a **Dockerfile**. | ||
*/ | ||
const dockerfile = (configs: DockerfileConfigs) => new DockerContainer(configs); | ||
|
||
/** | ||
* | ||
* A minimal API to assist tests that require containers or tests that run inside containers using a **docker-compose.yml**. | ||
*/ | ||
const compose = (configs: DockerComposeConfigs) => new DockerCompose(configs); | ||
|
||
/* c8 ignore next */ // c8 bug | ||
export const docker = { dockerfile, compose }; |
Oops, something went wrong.