Skip to content

Commit 9d6967f

Browse files
committed
feat(docker): build and publish unprivileged Docker image
Similar to swagger-editor This will allow to deploy Swagger-UI on clusters such as OpenShift without having to meddle with the security context and security context constraints.
1 parent 4680916 commit 9d6967f

File tree

4 files changed

+81
-4
lines changed

4 files changed

+81
-4
lines changed

.github/workflows/docker-build-push.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ jobs:
5656
- linux/arm64
5757
- linux/386
5858
- linux/ppc64le
59+
docker:
60+
- file: Dockerfile
61+
tag: ${{ needs.inputs.outputs.docker_tag }}
62+
- file: Dockerfile.unprivileged
63+
tag: ${{ needs.inputs.outputs.docker_tag }}-unprivileged
64+
5965
needs:
6066
- inputs
6167

@@ -82,6 +88,8 @@ jobs:
8288
with:
8389
context: .
8490
platforms: ${{ matrix.platform }}
91+
file: ${{ matrix.docker.file }}
92+
tags: ${{ matrix.docker.tag }}
8593
provenance: false
8694
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
8795

@@ -114,6 +122,12 @@ jobs:
114122
- inputs
115123
- build
116124

125+
strategy:
126+
matrix:
127+
tag:
128+
- ${{ needs.inputs.outputs.docker_tag }}
129+
- ${{ needs.inputs.outputs.docker_tag }}-unprivileged
130+
117131
steps:
118132
- name: Download digests
119133
uses: actions/download-artifact@v4
@@ -134,10 +148,10 @@ jobs:
134148
- name: Create manifest list and push
135149
working-directory: /tmp/digests
136150
run: |
137-
docker buildx imagetools create -t ${{ env.REGISTRY_IMAGE }}:${{ needs.inputs.outputs.docker_tag }} \
138-
${{ env.REGISTRY_IMAGE }}:${{ needs.inputs.outputs.docker_tag }} \
151+
docker buildx imagetools create -t ${{ env.REGISTRY_IMAGE }}:${{ matrix.tag }} \
152+
${{ env.REGISTRY_IMAGE }}:${{ matrix.tag }} \
139153
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
140154
141155
- name: Inspect image
142156
run: |
143-
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ needs.inputs.outputs.docker_tag }}
157+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ matrix.tag }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ COPY --chmod=0555 ./docker/docker-entrypoint.d/ /docker-entrypoint.d/
3131
COPY --chmod=0666 ./docker/configurator /usr/share/nginx/configurator
3232

3333
# Simulates running NGINX as a non root; in future we want to use nginxinc/nginx-unprivileged.
34-
# In future we will have separate unpriviledged images tagged as v5.1.2-unprivileged.
34+
# In future we will have separate unprivileged images tagged as v5.1.2-unprivileged.
3535
RUN chmod 777 /usr/share/nginx/html/ /etc/nginx/conf.d/ /etc/nginx/conf.d/default.conf /var/cache/nginx/ /var/run/
3636

3737
EXPOSE 8080

Dockerfile.unprivileged

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Looking for information on environment variables?
2+
# We don't declare them here — take a look at our docs.
3+
# https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md
4+
5+
FROM nginxinc/nginx-unprivileged:1.27.5-alpine
6+
7+
LABEL maintainer="vladimir.gorej@gmail.com" \
8+
org.opencontainers.image.authors="vladimir.gorej@gmail.com" \
9+
org.opencontainers.image.url="docker.swagger.io/swaggerapi/swagger-ui" \
10+
org.opencontainers.image.source="https://github.com/swagger-api/swagger-ui" \
11+
org.opencontainers.image.description="SwaggerUI Docker image" \
12+
org.opencontainers.image.licenses="Apache-2.0"
13+
14+
USER root
15+
16+
RUN apk add --update-cache --no-cache "nodejs" "libxml2>=2.13.4-r6" "libexpat>=2.7.0-r0" "libxslt>=1.1.42-r2" "xz-libs>=5.6.3-r1" "c-ares>=1.34.5-r0"
17+
RUN mkdir /etc/nginx/templates && \
18+
mkdir /usr/share/nginx/configurator && \
19+
# If user is set to a different ID at runtime, html must be writable by them too
20+
chown -R nginx:nginx /usr/share/nginx/html && \
21+
chmod a+rw /usr/share/nginx/html
22+
23+
USER nginx
24+
25+
LABEL maintainer="char0n"
26+
27+
ENV API_KEY="**None**" \
28+
SWAGGER_JSON="/app/swagger.json" \
29+
PORT="8080" \
30+
PORT_IPV6="" \
31+
BASE_URL="/" \
32+
SWAGGER_JSON_URL="" \
33+
CORS="true" \
34+
EMBEDDING="false"
35+
36+
COPY --chmod=0666 ./docker/default.conf.template ./docker/cors.conf ./docker/embedding.conf /etc/nginx/templates/
37+
38+
COPY --chown=nginx --chmod=0666 ./dist/* /usr/share/nginx/html/
39+
COPY --chmod=0555 ./docker/docker-entrypoint.d/ /docker-entrypoint.d/
40+
COPY --chown=nginx --chmod=0666 ./docker/configurator /usr/share/nginx/configurator
41+
42+
EXPOSE 8080

docs/development/docker.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Docker images
2+
3+
## Building locally
4+
5+
**Privileged image**:
6+
7+
```sh
8+
$ docker build . -t swaggerapi/swagger-ui:next
9+
$ docker run -d -p 8080:8080 swaggerapi/swagger-ui:next
10+
```
11+
12+
Now open your browser at `http://localhost:8080/`.
13+
14+
**Unprivileged image**:
15+
16+
```sh
17+
$ docker build . -f Dockerfile.unprivileged -t swaggerapi/swagger-ui:next-unprivileged
18+
$ docker run -d -p 8080:8080 swaggerapi/swagger-ui:next-unprivileged
19+
```
20+
21+
Now open your browser at `http://localhost:8080/`.

0 commit comments

Comments
 (0)