Skip to content

Commit 82bb011

Browse files
committed
refactor code
1 parent ff4bc42 commit 82bb011

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2976
-2276
lines changed

.golangci.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ linters:
1515
- nlreturn
1616
- cyclop
1717
- wrapcheck
18+
- funlen
19+
- errcheck
1820
enable-all: true
1921
linters-settings:
2022
funlen:
21-
lines: 80
23+
lines: 80
24+
gocognit:
25+
min-complexity: 90
26+
gocyclo:
27+
min-complexity: 50

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ VOLUME /app/backups /app/repos /app/ssl
33
WORKDIR /app
44
EXPOSE 80 443
55
ENV BIND=0.0.0.0:80 DOMAIN=localhost BACKUP=file:///app/backups
6-
RUN apk add --no-cache git docker-cli docker-compose openssl openssh-client && \
6+
RUN apk add --no-cache git docker docker-compose openssl openssh-client && \
77
mkdir -p /root/.ssh && \
88
echo -e 'Host *\n\tUserKnownHostsFile=/dev/null\n\tStrictHostKeyChecking no' > /root/.ssh/config && \
99
chmod 400 /root/.ssh

Dockerfile.light

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ VOLUME /app/backups /app/repos /app/ssl
33
WORKDIR /app
44
EXPOSE 80 443
55
ENV BIND=0.0.0.0:80 DOMAIN=localhost BACKUP=file:///app/backups
6-
RUN apk add --no-cache git docker-cli openssl openssh-client && \
6+
RUN apk add --no-cache git openssl openssh-client && \
77
mkdir -p /root/.ssh && \
88
echo -e 'Host *\n\tUserKnownHostsFile=/dev/null\n\tStrictHostKeyChecking no' > /root/.ssh/config && \
99
chmod 400 /root/.ssh

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ assemble-docs: build/git-pipe
3232
echo '\n\n## Usage\n\n' >> README.md
3333
stty rows 1024 cols 1024
3434
./build/git-pipe --help | grep ' ' | sed -n -r '/^\s+[a-z]/p' | tail -n +2 | sed -E 's/^\s+([a-z]+)\s+(.*)?/* `\1` - \2/' >> README.md
35-
./build/git-pipe --help | grep ' ' | sed -n -r '/^\s+[a-z]/p' | tail -n +2 | sed 's/^/* /'
3635
./build/git-pipe --help | grep ' ' | sed -n -r '/^\s+[a-z]/p' | tail -n +2 | awk '{print $$1}' | xargs -n 1 -i sh -c 'echo "\n## {}\n\`\`\`" >> README.md && ./build/git-pipe "{}" --help >> README.md && echo "\`\`\`\n" >> README.md'
3736

3837
README.md: assemble-docs

README.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ Wait a bit to finish building and go to
5353
* http://wordpress.wordpress-docker-compose.localhost:8080 - wordpress app
5454
* http://phpmyadmin.wordpress-docker-compose.localhost:8080 - for phpmyadmin app
5555

56+
## Automatic UI/dashboard
57+
58+
Index page automatically generated for unknown domain. Ex: http://localhost:8080
59+
60+
![image](https://user-images.githubusercontent.com/6597086/127631968-85a8eaa9-1605-4ca0-ba52-7943da536d1a.png)
61+
5662

5763

5864
## Supported OS
@@ -70,7 +76,7 @@ Wait a bit to finish building and go to
7076
* [ ] OIDC
7177
* [ ] support dynamic reconfiguration (over API/by file watch + signal)
7278
* [ ] support GitHub-like webhooks
73-
* [ ] lazy initialization
79+
* [ ] lazy initialization (ie: bring up service on request only)
7480
* [x] path routing as alternative to domain-based
7581

7682
## Installation
@@ -149,14 +155,13 @@ Flow:
149155
150156
* Deploys all services.
151157
* All ports in `ports` directive will be linked as sub-domains
152-
* Root compose file supports optional `x-domain` attribute which overrides domain prefix. Default is repo name (or FQDN)
153-
.
154-
* Each service with at least one port supports an optional `x-domain` attribute which overrides sub-domain. Default is
158+
* Each service with at least one port supports an optional `domainname` attribute which overrides sub-domain. Default is
155159
service name.
156160
* First services with attribute `x-root: yes` or with name `www`, `web`, `gateway` will be additionally exposed without
157161
sub-domain.
158162
* All exposed ports will be additionally exposed as sub-sub-domain with port name as the name.
159163
* Volumes automatically backup-ed and restored (see Backup)
164+
* Root port for service picked by the same rules as for [docker](#docker)
160165

161166
Domains will be generated as> `<port?>.<x-domain|service>.<x-domain|project>.<root-domain>`
162167
and `<x-domain|project>.<root-domain>` points to `<first x-root: true|www|web|gateway>`
@@ -190,25 +195,24 @@ Generated mapping (root domain (`-d,--domain,$DOMAIN`) is `localhost`):
190195
* `api.mini.localhost` - points `api` service to internal port `80`
191196
* `80.api.mini.localhost` - same
192197

193-
Root domain: `mini.localhost` points to `web` service to internal port `80` (the first service with name `web`, first port
194-
in array)
198+
Root domain: `mini.localhost` points to `web` service to internal port `80` (the first service with name `web`, first
199+
port in array)
195200

196201

197202

198203
### Override everything example
199204

200205
```yaml
201206
version: '3'
202-
x-domain: super
203207
services:
204208
web:
205-
x-domain: index
209+
domainname: index
206210
image: nginx
207211
ports:
208212
- 8080:80
209213
- 8081:9000
210214
api:
211-
x-domain: echo
215+
domainname: echo
212216
x-root: yes
213217
image: hashicorp/http-echo
214218
command: -listen :80 -text "web"
@@ -226,8 +230,8 @@ Generated mapping (root domain (`-d,--domain,$DOMAIN`) is `localhost`):
226230
* `echo.super.localhost` - points `api` service to internal port `80`
227231
* `80.echo.super.localhost` - same
228232

229-
Root domain: `super.localhost` points to `api` service to internal port `80` (the first service with `x-root: yes`, first
230-
port in array)
233+
Root domain: `super.localhost` points to `api` service to internal port `80` (the first service with `x-root: yes`,
234+
first port in array)
231235

232236

233237
## Backup
@@ -548,6 +552,27 @@ Example how to generate for multiple same clients:
548552

549553
git-pipe jwt -s changeme my-client-1 my-client-2 my-client-3 my-client-4
550554

555+
## Health check
556+
557+
git-pipe supports health checks in single Dockerfile repositories. It will not route traffic to the service until
558+
container will become healthy.
559+
560+
See [how to define health check in Dockerfile](https://docs.docker.com/engine/reference/builder/#healthcheck).
561+
562+
Example for common HTTP service:
563+
564+
```
565+
FROM my-service
566+
EXPOSE 80
567+
568+
569+
## ....
570+
HEALTHCHECK --interval=3s CMD curl -f http://localhost:80/health || exit 1
571+
572+
573+
## ...
574+
```
575+
551576
## Usage
552577

553578

_docs/03_docker-compose.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
55
* Deploys all services.
66
* All ports in `ports` directive will be linked as sub-domains
7-
* Root compose file supports optional `x-domain` attribute which overrides domain prefix. Default is repo name (or FQDN)
8-
.
9-
* Each service with at least one port supports an optional `x-domain` attribute which overrides sub-domain. Default is
7+
* Each service with at least one port supports an optional `domainname` attribute which overrides sub-domain. Default is
108
service name.
119
* First services with attribute `x-root: yes` or with name `www`, `web`, `gateway` will be additionally exposed without
1210
sub-domain.
1311
* All exposed ports will be additionally exposed as sub-sub-domain with port name as the name.
1412
* Volumes automatically backup-ed and restored (see Backup)
13+
* Root port for service picked by the same rules as for [docker](#docker)
1514

1615
Domains will be generated as> `<port?>.<x-domain|service>.<x-domain|project>.<root-domain>`
1716
and `<x-domain|project>.<root-domain>` points to `<first x-root: true|www|web|gateway>`
@@ -43,23 +42,22 @@ Generated mapping (root domain (`-d,--domain,$DOMAIN`) is `localhost`):
4342
* `api.mini.localhost` - points `api` service to internal port `80`
4443
* `80.api.mini.localhost` - same
4544

46-
Root domain: `mini.localhost` points to `web` service to internal port `80` (the first service with name `web`, first port
47-
in array)
45+
Root domain: `mini.localhost` points to `web` service to internal port `80` (the first service with name `web`, first
46+
port in array)
4847

4948
## Override everything example
5049

5150
```yaml
5251
version: '3'
53-
x-domain: super
5452
services:
5553
web:
56-
x-domain: index
54+
domainname: index
5755
image: nginx
5856
ports:
5957
- 8080:80
6058
- 8081:9000
6159
api:
62-
x-domain: echo
60+
domainname: echo
6361
x-root: yes
6462
image: hashicorp/http-echo
6563
command: -listen :80 -text "web"
@@ -77,5 +75,5 @@ Generated mapping (root domain (`-d,--domain,$DOMAIN`) is `localhost`):
7775
* `echo.super.localhost` - points `api` service to internal port `80`
7876
* `80.echo.super.localhost` - same
7977

80-
Root domain: `super.localhost` points to `api` service to internal port `80` (the first service with `x-root: yes`, first
81-
port in array)
78+
Root domain: `super.localhost` points to `api` service to internal port `80` (the first service with `x-root: yes`,
79+
first port in array)

_docs/11_healthcheck.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Health check
2+
3+
git-pipe supports health checks in single Dockerfile repositories. It will not route traffic to the service until
4+
container will become healthy.
5+
6+
See [how to define health check in Dockerfile](https://docs.docker.com/engine/reference/builder/#healthcheck).
7+
8+
Example for common HTTP service:
9+
10+
```
11+
FROM my-service
12+
EXPOSE 80
13+
# ....
14+
HEALTHCHECK --interval=3s CMD curl -f http://localhost:80/health || exit 1
15+
# ...
16+
```

_header.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ Wait a bit to finish building and go to
5353
* http://wordpress.wordpress-docker-compose.localhost:8080 - wordpress app
5454
* http://phpmyadmin.wordpress-docker-compose.localhost:8080 - for phpmyadmin app
5555

56+
## Automatic UI/dashboard
57+
58+
Index page automatically generated for unknown domain. Ex: http://localhost:8080
59+
60+
![image](https://user-images.githubusercontent.com/6597086/127631968-85a8eaa9-1605-4ca0-ba52-7943da536d1a.png)
61+
5662

5763

5864
## Supported OS
@@ -70,5 +76,5 @@ Wait a bit to finish building and go to
7076
* [ ] OIDC
7177
* [ ] support dynamic reconfiguration (over API/by file watch + signal)
7278
* [ ] support GitHub-like webhooks
73-
* [ ] lazy initialization
79+
* [ ] lazy initialization (ie: bring up service on request only)
7480
* [x] path routing as alternative to domain-based

cmd/git-pipe/command_jwt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"time"
66

77
"github.com/dgrijalva/jwt-go"
8-
"github.com/reddec/git-pipe/router"
8+
"github.com/reddec/git-pipe/core/ingress/embedded"
99
)
1010

1111
type CommandJWT struct {
@@ -21,7 +21,7 @@ type CommandJWT struct {
2121
func (cmd *CommandJWT) Execute([]string) error {
2222
now := time.Now()
2323
for _, name := range cmd.Args.Name {
24-
var claims router.JWTClaims
24+
var claims embedded.JWTClaims
2525
claims.Audience = name
2626
claims.Subject = cmd.Group
2727
claims.Methods = cmd.Methods

0 commit comments

Comments
 (0)