-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3902cc2
Showing
9 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: CI/CD | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
release: | ||
types: | ||
- published | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build_and_push: | ||
name: Build and push image | ||
permissions: | ||
contents: read | ||
id-token: write | ||
packages: write | ||
uses: significa/actions/.github/workflows/docker-image.yaml@main | ||
with: | ||
image_name: nginx-with-basic-auth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
/usr/bin/htpasswd -bc /etc/nginx/htpasswd "$BASIC_AUTH_USERNAME" "$BASIC_AUTH_PASSWORD" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
|
||
mkdir -p /usr/share/nginx/app-version | ||
echo -n "$APP_VERSION" > /usr/share/nginx/app-version/app-version.txt | ||
|
||
NGINX_CONF_PATH="/etc/nginx/conf.d/default.conf" | ||
|
||
if [ "$ENABLE_HEALTH_ROUTE" = "true" ]; then | ||
echo "Enabling /healthz route" | ||
sed -i 's/# include \/etc\/nginx\/healthz.conf;/include \/etc\/nginx\/healthz.conf;/' $NGINX_CONF_PATH | ||
fi | ||
|
||
if [ "$ENABLE_VERSION_ROUTE" = "true" ]; then | ||
echo "Enabling /healthz/version route" | ||
sed -i 's/# include \/etc\/nginx\/app_version.conf;/include \/etc\/nginx\/app_version.conf;/' $NGINX_CONF_PATH | ||
fi | ||
|
||
cat $NGINX_CONF_PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM nginx:1-alpine | ||
|
||
RUN apk update && \ | ||
apk add --no-cache apache2-utils && \ | ||
rm /var/cache/apk/* | ||
|
||
COPY ./nginx.conf /etc/nginx/conf.d/default.conf | ||
COPY ./healthz.conf ./app_version.conf /etc/nginx/ | ||
COPY ./40-basic-auth-htpasswd.sh ./50-setup-health-and-version.sh /docker-entrypoint.d/ | ||
|
||
ARG APP_VERSION=unknown | ||
ENV APP_VERSION=$APP_VERSION | ||
ENV ENABLE_HEALTH_ROUTE=true | ||
ENV ENABLE_VERSION_ROUTE=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Significa | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Nginx with Basic Auth Docker Image | ||
|
||
This is a simple, small, and multi-arch Docker image of Nginx with basic authentication enabled. | ||
|
||
**Example** | ||
|
||
```sh | ||
docker run \ | ||
-e BASIC_AUTH_USERNAME=your_username \ | ||
-e BASIC_AUTH_PASSWORD=your_password \ | ||
-v ./your/www/dir:/usr/share/nginx/html \ | ||
ghcr.io/significa/nginx-with-basic-auth | ||
``` | ||
|
||
Image name/url: `ghcr.io/significa/nginx-with-basic-auth` | ||
|
||
## Usage | ||
|
||
This image can be configured using environment variables during runtime. You do not need to prepare | ||
htpasswd encoded strings beforehand. Simply pass the environment variables in plaintext. | ||
|
||
|
||
**Required Environment Variables** | ||
|
||
* `BASIC_AUTH_USERNAME`: The username for basic authentication. | ||
* `BASIC_AUTH_PASSWORD`: The password for basic authentication. | ||
|
||
**Optional Environment Variables** | ||
|
||
These environment variables are optional and are used to enable `/healthz` and `/healthz/version`. | ||
This enables easy setup of health checks without dependency on the hosted web files and basic auth. | ||
They default to enabled (`true`) but can be set to `false` to disable them. | ||
The version route consumes the `APP_VERSION` env var (that can also be set via a build argument). | ||
|
||
* `ENABLE_HEALTH_ROUTE`: Enables the `/healthz` route. | ||
* `ENABLE_VERSION_ROUTE`: Enables the `/version/version` route. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
location /healthz/version { | ||
charset utf-8; | ||
alias /usr/share/nginx/app-version/; | ||
try_files /app-version.txt =404; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
location /healthz { | ||
charset utf-8; | ||
default_type text/plain; | ||
return 200 "OK"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
server { | ||
listen 80; | ||
listen [::]:80; | ||
server_name localhost; | ||
|
||
location / { | ||
root /usr/share/nginx/html; | ||
index index.html; | ||
charset utf-8; | ||
auth_basic "Restricted"; | ||
auth_basic_user_file /etc/nginx/htpasswd; | ||
} | ||
|
||
# include /etc/nginx/healthz.conf; | ||
# include /etc/nginx/app_version.conf; | ||
|
||
error_page 500 502 503 504 /50x.html; | ||
location = /50x.html { | ||
root /usr/share/nginx/html; | ||
} | ||
} |