Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Traefik
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Composer
library
Traefik
Commits
d9f144dd
Commit
d9f144dd
authored
4 years ago
by
jurgenhaas
Browse files
Options
Downloads
Patches
Plain Diff
#6
Update traefik config to version 2
parent
52e9481c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Traefik.php
+73
-22
73 additions, 22 deletions
Traefik.php
with
73 additions
and
22 deletions
Traefik.php
+
73
−
22
View file @
d9f144dd
...
...
@@ -72,43 +72,31 @@ class Traefik {
/**
* Update the Traefik container.
*
* @param bool $rewrite
*/
public
function
update
():
void
{
public
function
update
(
$rewrite
=
FALSE
):
void
{
// Update host wider traefik container.
$traefikPath
=
$_SERVER
[
'HOME'
]
.
'/.traefik'
;
$traefikCertPath
=
$_SERVER
[
'HOME'
]
.
'/.traefik/certs'
;
$traefikConfigPath
=
$_SERVER
[
'HOME'
]
.
'/.traefik/configuration'
;
$traefikFile
=
$traefikPath
.
'/docker-compose.yml'
;
$fs
=
new
Filesystem
();
if
(
$fs
->
exists
(
$traefikFile
))
{
if
(
!
$rewrite
&&
$fs
->
exists
(
$traefikFile
))
{
$traefik
=
Yaml
::
parse
(
file_get_contents
(
$traefikFile
));
}
else
{
$fs
->
mkdir
(
$traefikPath
);
$traefik
=
[
'version'
=>
'3'
,
'services'
=>
[
'traefik'
=>
[
'image'
=>
'traefik:1.7.17'
,
'restart'
=>
'unless-stopped'
,
'command'
=>
'-c /dev/null --web --docker --defaultEntryPoints="https" --defaultEntryPoints="http" --entryPoints="Name:https Address::443 TLS:/certs/'
.
$this
->
cert_filename
.
',/certs/'
.
$this
->
key_filename
.
'" --entryPoints="Name:http Address::80"'
,
'networks'
=>
[],
'ports'
=>
[
$this
->
http_port
.
':80'
,
$this
->
https_port
.
':443'
,
],
'volumes'
=>
[
'./certs:/certs/'
,
'/var/run/docker.sock:/var/run/docker.sock'
,
],
],
],
'networks'
=>
[],
];
$traefik
=
$this
->
defaultDockerCompose
();
}
if
(
!
$fs
->
exists
(
$traefikCertPath
))
{
$fs
->
mkdir
(
$traefikCertPath
);
}
if
(
!
$fs
->
exists
(
$traefikConfigPath
))
{
$fs
->
mkdir
(
$traefikConfigPath
);
}
file_put_contents
(
$traefikConfigPath
.
'/certificates.toml'
,
$this
->
defaultCertificatesConfig
());
if
(
!
in_array
(
$this
->
name
,
$traefik
[
'services'
][
'traefik'
][
'networks'
],
TRUE
))
{
$traefik
[
'services'
][
'traefik'
][
'networks'
][]
=
$this
->
name
;
...
...
@@ -123,4 +111,67 @@ class Traefik {
}
}
/**
* @return array
*/
private
function
defaultDockerCompose
():
array
{
return
[
'version'
=>
'3'
,
'services'
=>
[
'traefik'
=>
[
'image'
=>
'traefik:v2.3'
,
'command'
=>
[
'--api=true'
,
'--api.dashboard=true'
,
'--api.insecure=true'
,
'--entrypoints.web.address=:'
.
$this
->
http_port
,
'--entrypoints.websecure.address=:'
.
$this
->
https_port
,
'--entrypoints.websecure.http.tls.domains[0].main='
.
$this
->
domain
,
'--entrypoints.websecure.http.tls.domains[0].sans=.'
.
$this
->
domain
,
'--providers.file.directory=/configuration/'
,
'--providers.file.watch=true'
,
'--providers.docker=true'
,
'--providers.docker.exposedbydefault=false'
,
],
'restart'
=>
'unless-stopped'
,
'networks'
=>
[
'internal'
,
],
'ports'
=>
[
$this
->
http_port
.
':80'
,
$this
->
https_port
.
':443'
,
],
'labels'
=>
[
'traefik.enable=true'
,
'traefik.network=internal'
,
'traefik.http.routers.traefik.service=api@internal'
,
'traefik.http.routers.traefik.rule=Host(`traefik.'
.
$this
->
domain
.
'`)'
,
],
'volumes'
=>
[
'./certs:/certs/:ro'
,
'./configuration:/configuration/:ro'
,
'/var/run/docker.sock:/var/run/docker.sock:ro'
,
],
],
],
'networks'
=>
[
'internal'
=>
[
'internal'
=>
true
,
],
],
];
}
/**
* @return string
*/
private
function
defaultCertificatesConfig
():
string
{
return
<<<EOF
[[tls.certificates]]
certFile = "/certs/$this->cert_filename"
keyFile = "/certs/$this->key_filename"
EOF;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment