Skip to content

Commit

Permalink
feat: build Caddy binary
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Oct 18, 2023
1 parent 66d6bad commit 393d498
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 14 deletions.
93 changes: 87 additions & 6 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ release:
env:
- CGO_ENABLED=0
builds:
- id: caddy
dir: caddy/vulcain
ldflags:
- -X 'github.com/caddyserver/caddy/v2.CustomVersion=Vulcain.rocks {{ .Version }} Caddy'
goos:
- linux
- darwin
- windows
goarch:
- "386"
- amd64
- arm
- arm64
goarm:
- "5"
- "6"
- "7"
# Legacy build
- id: legacy
dir: cmd/vulcain
env:
Expand All @@ -37,11 +55,28 @@ builds:
- goos: darwin
goarch: '386'
archives:
- builds:
- caddy
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
files:
- COPYRIGHT
- LICENSE
- README.md
- Caddyfile
format_overrides:
- goos: windows
format: zip
- id: legacy
builds:
- legacy
name_template: >-
{{ .ProjectName }}_
{{ .ProjectName }}-legacy_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
Expand All @@ -56,9 +91,55 @@ archives:
format: zip
dockers:
- ids:
- legacy
- caddy
goos: linux
goarch: amd64
image_templates:
- "dunglas/vulcain:{{ .Tag }}-amd64"
- "dunglas/vulcain:v{{ .Major }}-amd64"
- "dunglas/vulcain:v{{ .Major }}.{{ .Minor }}-amd64"
- "dunglas/vulcain:latest-amd64"
use: buildx
build_flag_templates:
- "--platform=linux/amd64"
extra_files:
- Caddyfile
- ids:
- caddy
goos: linux
goarch: arm64
image_templates:
- "dunglas/vulcain:{{ .Tag }}-arm64v8"
- "dunglas/vulcain:v{{ .Major }}-arm64v8"
- "dunglas/vulcain:v{{ .Major }}.{{ .Minor }}-arm64v8"
- "dunglas/vulcain:latest-arm64v8"
use: buildx
build_flag_templates:
- "--platform=linux/arm64/v8"
extra_files:
- Caddyfile
- ids:
- legacy
dockerfile: legacy.Dockerfile
image_templates:
- "dunglas/vulcain:legacy-{{ .Tag }}"
- "dunglas/vulcain:legacy-v{{ .Major }}"
- "dunglas/vulcain:legacy-v{{ .Major }}.{{ .Minor }}"
- "dunglas/vulcain:legacy-latest"
docker_manifests:
- name_template: dunglas/vulcain:{{ .Tag }}
image_templates:
- dunglas/vulcain:{{ .Tag }}-amd64
- dunglas/vulcain:{{ .Tag }}-arm64v8
- name_template: dunglas/vulcain:v{{ .Major }}
image_templates:
- dunglas/vulcain:v{{ .Major }}-amd64
- dunglas/vulcain:v{{ .Major }}-arm64v8
- name_template: dunglas/vulcain:v{{ .Major }}.{{ .Minor }}
image_templates:
- dunglas/vulcain:v{{ .Major }}.{{ .Minor }}-amd64
- dunglas/vulcain:v{{ .Major }}.{{ .Minor }}-arm64v8
- name_template: dunglas/vulcain:latest
image_templates:
- 'dunglas/vulcain:{{ .Tag }}'
- 'dunglas/vulcain:v{{ .Major }}'
- 'dunglas/vulcain:v{{ .Major }}.{{ .Minor }}'
- 'dunglas/vulcain:latest'
- dunglas/vulcain:latest-amd64
- dunglas/vulcain:latest-arm64v8
20 changes: 20 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
order vulcain before request_header

{$CADDY_GLOBAL_OPTIONS}
}

{$CADDY_EXTRA_CONFIG}

{$SERVER_NAME:localhost} {
vulcain {
#openapi_file ../../fixtures/openapi.yaml
#max_pushes 0
#early_hints
}
log
encode zstd gzip
reverse_proxy {env.VULCAIN_UPSTREAM}

{$CADDY_SERVER_EXTRA_DIRECTIVES}
}
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM scratch
COPY vulcain /
CMD ["./vulcain"]
EXPOSE 80 443
FROM caddy:2-alpine

COPY vulcain /usr/bin/caddy
COPY Caddyfile /etc/caddy/Caddyfile
16 changes: 16 additions & 0 deletions docs/gateway/caddy.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,27 @@ The Vulcain module for Caddy allows to turn any existing web API in a one suppor

## Install

### Docker

The easiest way to get started is to use Docker:

```console
docker run -e VULCAIN_UPSTREAM='http://your-api' -p 80:80 -p 443:443 dunglas/vulcain
```

The configuration file is located at `/etc/caddy/Caddyfile`.

### Binaries

1. Go on [the Caddy server download page](https://caddyserver.com/download)
2. Select the `github.com/dunglas/vulcain/caddy` module
3. Select other modules you're interested in such as [the cache module](https://github.com/caddyserver/cache-handler) or [Mercure](https://mercure.rocks) (optional)
4. Download and enjoy!

Alternatively, you can use [xcaddy](https://github.com/caddyserver/xcaddy) to create a custom build of Caddy containing the Vulcain module: `xcaddy build --with github.com/dunglas/vulcain/caddy`

Pre-built binaries are also available for download [on the releases page](https://github.com/dunglas/vulcain/releases).

## Configuration

Example configuration:
Expand All @@ -37,6 +51,8 @@ example.com {
}
```

All other [Caddyfile directives](https://caddyserver.com/docs/caddyfile) are also supported.

## Start the Server

Just run `./caddy run`.
Expand Down
4 changes: 2 additions & 2 deletions docs/gateway/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ A Docker image is available on Docker Hub. The following command is enough to ge
-v /your/tls/certs:/tls \
-e UPSTREAM='http://your-api' -e KEY_FILE='tls/key.pem' -e CERT_FILE='tls/cert.pem' \
-p 443:443 \
dunglas/vulcain
dunglas/vulcain:legacy-latest

The gateway is available on `https://localhost`.

Expand All @@ -60,7 +60,7 @@ In production, run:
docker run \
-e UPSTREAM='http://your-api' -e ACME_HOSTS='example.com' \
-p 80:80 -p 443:443 \
dunglas/vulcain
dunglas/vulcain:legacy-latest

Be sure to update the value of `ACME_HOSTS` to match your domain name(s), a Let's Encrypt TLS certificate will be automatically generated.

Expand Down
4 changes: 2 additions & 2 deletions docs/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

[Les-Tilleuls.coop](https://les-tilleuls.coop) provides professional services for Vulcain including training, development and API design.

[Contact Les-Tilleuls.coop](https://les-tilleuls.coop/en/contact) for more information.
[Contact Les-Tilleuls.coop](https://les-tilleuls.coop/#contact) for more information.

## Training

[Masterclass](https://masterclass.les-tilleuls.coop) organizes official training sessions about the Mercure protocol (available in English and in French).
[Masterclass](https://les-tilleuls.coop/masterclass) organizes official training sessions about Vulcain (available in English and in French).
5 changes: 5 additions & 0 deletions legacy.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM gcr.io/distroless/static
COPY vulcain /
CMD ["/vulcain"]
EXPOSE 80 443

0 comments on commit 393d498

Please sign in to comment.