Skip to content

Commit

Permalink
Merge pull request #8 from Totodore/networks-support
Browse files Browse the repository at this point in the history
Networks support
  • Loading branch information
Totodore authored Dec 8, 2020
2 parents c1cd1a0 + 7882ea0 commit 42c72ed
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
},
"devDependencies": {
"@types/dockerode": "^3.2.1",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.9",
"tsc-watch": "^4.2.9",
"typescript": "^4.1.2"
Expand Down
13 changes: 10 additions & 3 deletions src/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class DockerManager {
for (const container of containers) {
const labels: DockerCiLabels = container.Labels;
if (labels["docker-ci.enable"] === "true")
response[container.Id] = labels["docker-ci.name"] || (await this.getContainer(container.Id).inspect()).Name;
response[container.Id] = labels["docker-ci.name"] || (await this.getContainer(container.Id).inspect()).Name.replace("/", "")
}
return response;
}
Expand Down Expand Up @@ -85,13 +85,20 @@ export class DockerManager {
* @param containerId
*/
public async recreateContainer(containerId: string) {
const container = this.getContainer(containerId);
let container: Docker.Container = this.getContainer(containerId);
const infos = await container.inspect();
this._logger.log("Stopping container");
await container.stop();
this._logger.log("Removing container");
await container.remove();
this._logger.log("Recreating container");
(await this._docker.createContainer({ ...infos.Config, name: infos.Name })).start();
container = await this._docker.createContainer({
...infos.Config,
name: infos.Name,
NetworkingConfig: {
EndpointsConfig: infos.NetworkSettings.Networks
}
});
container.start();
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class App {
try {
const containerInfos = await this._dockerManager.getContainer(res.Actor.ID).inspect();
const labels: DockerCiLabels = containerInfos.Config.Labels;
const routeId = labels["docker-ci.name"] || containerName;
const routeId = labels["docker-ci.name"] || containerName.replace("/", "");
if (labels["docker-ci.enable"] === "true") {
this._logger.log("Docker-ci enabled, adding container to webhook conf");
this._addContainerConf(routeId, containerInfos.Id);
Expand Down
9 changes: 8 additions & 1 deletion test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ version: "3"
services:
app:
image: "httpd"
container_name: httpd
networks:
- "web"
labels:
- "docker-ci.enable=true"
- "docker-ci.name=hello-world"
- "docker-ci.name=hello-world"

networks:
web:
external: true

0 comments on commit 42c72ed

Please sign in to comment.