forked from deliveroo/nginx-sidecar
-
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
1 parent
f1b95b8
commit 155e50f
Showing
9 changed files
with
241 additions
and
70 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,104 @@ | ||
name: Docker | ||
|
||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
# Publish semver tags as releases. | ||
tags: [ 'v*.*.*' ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
env: | ||
# Use docker.io for Docker Hub if empty | ||
REGISTRY: ghcr.io | ||
# github.repository as <account>/<repo> | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
# This is used to complete the identity challenge | ||
# with sigstore/fulcio when running outside of PRs. | ||
id-token: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
# # https://github.com/docker/setup-qemu-action | ||
# - name: Set up QEMU | ||
# uses: docker/setup-qemu-action@v2.0.0 | ||
|
||
# https://github.com/docker/setup-buildx-action | ||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v2.0.0 | ||
|
||
# Login against a Docker registry except on PR | ||
# https://github.com/docker/login-action | ||
- name: Log into registry ${{ env.REGISTRY }} | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v2.0.0 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Extract metadata (tags, labels) for Docker | ||
# https://github.com/docker/metadata-action | ||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@v4.0.1 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
type=semver,pattern={{major}} | ||
# Cache dependencies | ||
# https://github.com/actions/cache | ||
- name: Cache Docker layers | ||
uses: actions/cache@v3.0.5 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-multi-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-multi-buildx | ||
# Build and push Docker image with Buildx (don't push on PR) | ||
# https://github.com/docker/build-push-action | ||
- name: Build and push Docker image | ||
id: build-and-push | ||
uses: docker/build-push-action@v3.1.0 | ||
with: | ||
context: . | ||
# platforms: linux/amd64,linux/arm64,linux/arm/v7 | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
# Note the mode=max here | ||
# More: https://github.com/moby/buildkit#--export-cache-options | ||
# And: https://github.com/docker/buildx#--cache-tonametypetypekeyvalue | ||
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new | ||
|
||
# Temp fix / Disabled on self-hosted runner | ||
# https://github.com/docker/build-push-action/issues/252 | ||
# https://github.com/moby/buildkit/issues/1896 | ||
- name: Move cache | ||
run: | | ||
rm -rf /tmp/.buildx-cache | ||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
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
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 |
---|---|---|
@@ -1,9 +1,18 @@ | ||
FROM nginx:stable | ||
|
||
RUN apt update && apt install -y curl | ||
# # Install dependencies | ||
# ARG DEPENDENCIES="curl" | ||
# RUN apt-get update -y && \ | ||
# apt-get install --no-install-recommends -y ${DEPENDENCIES} && \ | ||
# apt-get clean && \ | ||
# rm -rf /var/cache/apt/archives/* && \ | ||
# rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ | ||
# truncate -s 0 /var/log/*log | ||
|
||
COPY nginx.conf.template /etc/nginx/nginx.conf.template | ||
COPY start.sh /usr/bin/start.sh | ||
RUN chmod a+x /usr/bin/start.sh | ||
COPY entrypoint.sh /entrypoint.sh | ||
RUN chmod a+x /entrypoint.sh && \ | ||
mkdir -p /usr/local/etc/nginx | ||
|
||
CMD /usr/bin/start.sh | ||
COPY *.conf.template /usr/local/etc/nginx/ | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
0.3.8 | ||
0.4.0 |
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,32 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# nginx.conf doesn't support environment variables, so we substitute at run time. | ||
# Proxy setup was moved in external file. | ||
|
||
## nginx.conf substitutions: | ||
/bin/sed \ | ||
-e "s/<NGINX_PORT>/${NGINX_PORT:-80}/g" \ | ||
-e "s/<NGINX_CLIENT_BODY_BUFFER_SIZE>/${NGINX_CLIENT_BODY_BUFFER_SIZE:-8k}/g" \ | ||
-e "s/<NGINX_CLIENT_MAX_BODY_SIZE>/${NGINX_CLIENT_MAX_BODY_SIZE:-5M}/g" \ | ||
-e "s/<NGINX_STATUS_PORT>/${NGINX_STATUS_PORT:-81}/g" \ | ||
-e "s:<NGINX_STATUS_ALLOW_FROM>:${NGINX_STATUS_ALLOW_FROM:-all}:g" \ | ||
/usr/local/etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf | ||
|
||
## proxy.conf substitutions: | ||
/bin/sed \ | ||
-e "s/<NGINX_PROXY_BUFFER_SIZE>/${NGINX_PROXY_BUFFER_SIZE:-8k}/g" \ | ||
-e "s:<NGINX_PROXY_TIMEOUT>:${NGINX_PROXY_TIMEOUT:-60s}:g" \ | ||
-e "s/<APP_SCHEME>/${APP_SCHEME:-http}/g" \ | ||
-e "s/<APP_HOST>/${APP_HOST:-app}/g" \ | ||
-e "s/<APP_PORT>/${APP_PORT:-8080}/g" \ | ||
/usr/local/etc/nginx/proxy.conf.template > /etc/nginx/proxy.conf | ||
|
||
# Wait for the application to start before accepting ALB requests. | ||
if [[ -z "${SKIP_HEALTHCHECK}" ]]; then | ||
curl --silent --fail --max-time 5 "http://${APP_HOST:-app}:${APP_PORT:-8080}${APP_HEALTHCHECK_PATH:-/health}" || exit 1 | ||
fi | ||
|
||
# run in foreground as pid 1 | ||
exec /usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf |
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
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,35 @@ | ||
proxy_pass_request_headers on; | ||
|
||
# For NewRelic, time in milliseconds | ||
proxy_set_header X-Request-Start "t=${msec}"; | ||
proxy_set_header X-Queue-Start "t=${msec}"; | ||
|
||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $thescheme; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-Host $http_host; | ||
|
||
# Pass the original host name through, this is important if downstream | ||
# uses host based routing | ||
proxy_set_header Host $host; | ||
|
||
proxy_redirect off; # disable nginx redirect-rewrite logic | ||
proxy_pass <APP_SCHEME>://<APP_HOST>:<APP_PORT>; # default http://app:8080 | ||
|
||
# The size of the buffer that stores the response headers | ||
proxy_buffer_size <NGINX_PROXY_BUFFER_SIZE>; | ||
|
||
# Websocket support | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "upgrade"; | ||
|
||
proxy_http_version 1.1; | ||
|
||
# Cache support | ||
proxy_cache_bypass $http_upgrade; | ||
|
||
# timeout settings when proxying request to a server upstream | ||
# nginx default values for these can be high for your app needs so it is configurable | ||
proxy_connect_timeout <NGINX_PROXY_TIMEOUT>; | ||
proxy_send_timeout <NGINX_PROXY_TIMEOUT>; | ||
proxy_read_timeout <NGINX_PROXY_TIMEOUT>; |