Skip to content

Commit 68d7fbb

Browse files
authored
Merge pull request #5 from secondlife/signal/static
Add configurable static asset hosting
2 parents a49f4d5 + 9ac3eea commit 68d7fbb

File tree

9 files changed

+140
-1141
lines changed

9 files changed

+140
-1141
lines changed

.github/workflows/ci.yaml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
name: Test & Build
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
tags:
8-
- 'v*'
94
pull_request:
5+
push:
6+
branches: [main]
7+
tags: [v*]
108

119
jobs:
1210
test:
13-
runs-on: [self-hosted, linux, x64]
11+
name: Test
12+
runs-on: [self-hosted, linux]
1413
steps:
15-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v3
1615
- name: Run tests
1716
run: docker build --target test .
18-
docker:
17+
build:
18+
name: Build
19+
runs-on: [self-hosted, linux]
1920
needs: test
20-
uses: secondlife/docker-build-workflow/.github/workflows/build.yaml@v3
21-
with:
22-
image: platform/nginx-proxy
23-
platforms: linux/amd64,linux/arm64
24-
push: true
25-
promote: ${{ startsWith(github.ref, 'refs/tags/v') }}
26-
secrets:
27-
github_pat: ${{ secrets.SHARED_GITHUB_TOKEN }}
28-
jfrog_token: ${{ secrets.SHARED_JFROG_TOKEN }}
21+
steps:
22+
- uses: actions/checkout@v3
23+
- uses: secondlife/action-build-docker@v1
24+
with:
25+
image: platform/nginx-proxy
26+
platforms: linux/amd64,linux/arm64
27+
promote: ${{ startsWith(github.ref, 'refs/tags/v') }}
28+
jfrog-token: ${{ secrets.SHARED_JFROG_TOKEN }}

Dockerfile

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
1+
############
2+
# Gomplate
3+
############
4+
FROM artifactory.secondlife.io/dockerhub/alpine:3 AS gomplate
5+
ARG TARGETPLATFORM=linux/amd64
6+
ARG GOMPLATE_VERSION=3.10.0
7+
ARG GOMPLATE_AMD64_SHA256=603539aac4e09f98a8ca5b6e5da0c21213221206dc7175a5644255c7a22b936d
8+
ARG GOMPLATE_ARM64_SHA256=3352ef521977ee39cdd406a9a7943d0b5f29772e5542995416bf093b90bbae2c
9+
RUN apk add --no-cache curl bash
10+
SHELL ["/bin/bash", "-c"]
11+
RUN ARCH=${TARGETPLATFORM/linux\//} \
12+
&& curl -Lf https://github.com/hairyhenderson/gomplate/releases/download/v${GOMPLATE_VERSION}/gomplate_linux-${ARCH}-slim -o /tmp/gomplate \
13+
&& sha_envvar="GOMPLATE_${ARCH^^}_SHA256" \
14+
&& GOMPLATE_SHA256="${!sha_envvar}" \
15+
&& echo "${GOMPLATE_SHA256} /tmp/gomplate" | sha256sum -c \
16+
&& chmod +x /tmp/gomplate
17+
118
############
219
# Base
320
############
4-
ARG ARCH=
5-
FROM artifactory.secondlife.io/dockerhub/${ARCH}alpine:3 AS base
21+
FROM artifactory.secondlife.io/dockerhub/alpine:3 AS base
22+
COPY --from=gomplate /tmp/gomplate /usr/local/bin/
623
RUN apk add --no-cache \
7-
bash \
8-
nginx \
9-
nginx-mod-http-headers-more
24+
bash \
25+
nginx \
26+
nginx-mod-http-headers-more
1027
COPY src /
1128
ENV LISTEN_PORT=80
29+
ENV STATIC_LOCATIONS=
1230
EXPOSE 80
1331
STOPSIGNAL SIGQUIT
1432
ENTRYPOINT ["/docker-entrypoint.sh"]

README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,50 @@ Pair nginx-proxy with your favorite upstream server (wsgi, uwsgi, asgi, et al.)
1111
| `PROXY_REVERSE_URL` | Upstream server URL | Yes | | http://myapp:8080 |
1212
| `LISTEN_PORT` | Server port | Yes | 8080 | |
1313
| `SILENT` | Silence entrypoint output | No | | |
14+
| `STATIC_LOCATIONS` | Static asset mappings | No | | |
15+
16+
### Hosting Static Assets
17+
18+
Static files can be hosted from your proxied application by sharing a volume
19+
mount between nginx-proxy and your app container then defining a list of
20+
hosted directories using `STATIC_LOCATIONS`.
21+
22+
In ECS, you can mount directies with with the `volumesFrom` directive. With
23+
docker-compose like so:
24+
25+
```yaml
26+
services:
27+
app:
28+
# ...
29+
volumes:
30+
static:/var/www/static
31+
proxy:
32+
# ...
33+
environment:
34+
STATIC_LOCATIONS:/static/:/var/www/static/
35+
volumes:
36+
static:/var/www/static
37+
volumes:
38+
static:
39+
```
40+
41+
The syntax of `STATIC_LOCATIONS` is `HOSTED_PATH1:LOCAL_PATH1,HOSTED_PATH2:LOCAL_PATH2`
1442

1543
## Development
1644

1745
A test suite is baked into nginx-proxy's Dockerfile. You can run it by building
1846
the test layer: `docker build --target test .`
1947

20-
[nginx container]: https://hub.docker.com/_/nginx
21-
[mo]: https://github.com/tests-always-included/mo
22-
2348
### Differences from standard nginx container
2449

2550
Notable differences from the official [nginx container][]
2651

27-
- [mo][] is used to render nginx configuration templates so that image startup
52+
- [gomplate][] is used to render nginx configuration templates so that image startup
2853
is aborted if a template variable is missing. This is an improvement over the
2954
official image, which uses `envsubst`.
3055
- alpine's official nginx package is used in order to ensure compatibility with
3156
distro-provided nginx modules. This is another enhancement, as the official
3257
image cannot be used with alpine's nginx modules.
58+
59+
[nginx container]: https://hub.docker.com/_/nginx
60+
[gomplate]: https://docs.gomplate.ca/

src/docker-entrypoint.d/00-render-templates.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ do
99
final=$(basename "$f")
1010
final=${final%.template}
1111
final="/etc/nginx/conf.d/$final"
12-
cat "$f" | mo --fail-not-set --fail-on-function > "$final"
12+
cat "$f" | gomplate > "$final"
1313
log "$0: Rendered $f and moved it to $final"
1414
done
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
server {
2-
listen {{LISTEN_PORT}};
2+
listen {{ .Env.LISTEN_PORT }};
33
server_name localhost;
44
add_header X-Request-ID $request_id;
55

@@ -9,7 +9,16 @@ server {
99
add_header X-Content-Type-Options "nosniff";
1010

1111
location / {
12-
proxy_pass {{PROXY_REVERSE_URL}};
12+
proxy_pass {{ .Env.PROXY_REVERSE_URL }};
1313
proxy_set_header X-Request-ID $request_id;
1414
}
15+
16+
{{ if .Env.STATIC_LOCATIONS }}
17+
{{ range (.Env.STATIC_LOCATIONS | strings.Split "," )}}
18+
{{ $l := (. | strings.Split ":" )}}
19+
location {{index $l 0 }} {
20+
alias {{index $l 1 }};
21+
}
22+
{{ end }}
23+
{{ end }}
1524
}

0 commit comments

Comments
 (0)