Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit bddfe54

Browse files
committed
fix: make DOCKER_CONTAINER_HOSTNAME and DOCKER_DOMAIN_NAME optionnal because kernels can not not allow to set them
1 parent 4829661 commit bddfe54

File tree

1 file changed

+60
-56
lines changed

1 file changed

+60
-56
lines changed

src/docker.ts

Lines changed: 60 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -87,65 +87,69 @@ export default {
8787
},
8888
process.env.DOCKER_NETWORK_ALIASES || ''
8989
);
90-
const hostName = data.replaceTokens(
91-
{
92-
prId: prId,
93-
ref: ref,
94-
sha: sha,
90+
const containerData: any = {
91+
Image: process.env.DOCKER_IMAGE,
92+
name: containerName,
93+
Volumes: (process.env.DOCKER_VOLUMES || '').split(',').reduce(
94+
(accumulator, target) => ({
95+
...accumulator,
96+
[target]: {},
97+
}),
98+
{}
99+
),
100+
WorkingDir: process.env.DOCKER_WORKDIR,
101+
HostConfig: {
102+
DnsSearch: (process.env.DOCKER_DNS_SEARCH || '').split(','),
103+
NetworkMode: process.env.DOCKER_NETWORK_MODE,
104+
Binds: (process.env.DOCKER_BINDS || '').split(','),
105+
...optionalHostConfig,
95106
},
96-
process.env.DOCKER_CONTAINER_HOSTNAME || ''
97-
);
98-
docker.container
99-
.create({
100-
Image: process.env.DOCKER_IMAGE,
101-
name: containerName,
102-
Hostname: hostName,
103-
Domainname: data.replaceTokens(
104-
{
105-
prId: prId,
106-
ref: ref,
107-
sha: sha,
108-
},
109-
process.env.DOCKER_DOMAIN_NAME || ''
110-
),
111-
Volumes: (process.env.DOCKER_VOLUMES || '').split(',').reduce(
112-
(accumulator, target) => ({
113-
...accumulator,
114-
[target]: {},
115-
}),
116-
{}
117-
),
118-
WorkingDir: process.env.DOCKER_WORKDIR,
119-
HostConfig: {
120-
DnsSearch: (process.env.DOCKER_DNS_SEARCH || '').split(','),
121-
NetworkMode: process.env.DOCKER_NETWORK_MODE,
122-
Binds: (process.env.DOCKER_BINDS || '').split(','),
123-
...optionalHostConfig,
124-
},
125-
Entrypoint: process.env.DOCKER_ENTRYPOINT,
126-
Env: [
127-
'REF_DIRECTORY=/refs',
128-
'GIT_URL=' + cloneUrl,
129-
'GIT_BRANCH=' + ref,
130-
'GIT_SHA=' + sha,
131-
'RANDOM_STRING=' + randomString,
132-
compiledPhpMyAdminConfig === null
133-
? ''
134-
: 'PMA_CONFIG=' + compiledPhpMyAdminConfig,
135-
],
136-
NetworkingConfig: {
137-
EndpointsConfig: createAliasesFromString(networkAliases),
107+
Entrypoint: process.env.DOCKER_ENTRYPOINT,
108+
Env: [
109+
'REF_DIRECTORY=/refs',
110+
'GIT_URL=' + cloneUrl,
111+
'GIT_BRANCH=' + ref,
112+
'GIT_SHA=' + sha,
113+
'RANDOM_STRING=' + randomString,
114+
compiledPhpMyAdminConfig === null ? '' : 'PMA_CONFIG=' + compiledPhpMyAdminConfig,
115+
],
116+
NetworkingConfig: {
117+
EndpointsConfig: createAliasesFromString(networkAliases),
118+
},
119+
Labels: {
120+
[labelNamespace]: 'true',
121+
[labelNamespace + '.git-url']: cloneUrl,
122+
[labelNamespace + '.git-ref']: ref,
123+
[labelNamespace + '.git-sha']: sha,
124+
[labelNamespace + '.github-type']: 'pull-request',
125+
[labelNamespace + '.github-pr-id']: '' + prId,
126+
},
127+
};
128+
const domainName = process.env.DOCKER_DOMAIN_NAME || '';
129+
if (domainName.length > 0) {
130+
containerData.Domainname = data.replaceTokens(
131+
{
132+
prId: prId,
133+
ref: ref,
134+
sha: sha,
138135
},
139-
Labels: {
140-
[labelNamespace]: 'true',
141-
[labelNamespace + '.git-url']: cloneUrl,
142-
[labelNamespace + '.git-ref']: ref,
143-
[labelNamespace + '.git-sha']: sha,
144-
[labelNamespace + '.github-type']: 'pull-request',
145-
[labelNamespace + '.github-pr-id']: '' + prId,
146-
[labelNamespace + '.public-dns-hostname']: hostName,
136+
domainName
137+
);
138+
}
139+
const hostName = process.env.DOCKER_CONTAINER_HOSTNAME || '';
140+
if (hostName.length > 0) {
141+
containerData.Hostname = data.replaceTokens(
142+
{
143+
prId: prId,
144+
ref: ref,
145+
sha: sha,
147146
},
148-
})
147+
hostName
148+
);
149+
containerData.Labels[labelNamespace + '.public-dns-hostname'] = hostName;
150+
}
151+
docker.container
152+
.create(containerData)
149153
.then((container) => container.start())
150154
.then((container) => {
151155
let c = new Container(container.id, repoName);

0 commit comments

Comments
 (0)