Skip to content

Commit

Permalink
MVP (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
amorey authored Jun 28, 2024
1 parent 9d6b915 commit af2696e
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 24 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: publish

on:
push:
tags:
- '**'

jobs:
build-and-publish-amd64:
runs-on: ubuntu-latest
steps:
- name: Get tag name
uses: olegtarasov/[email protected]
id: tagName
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: kubetail/echoserver:${{ steps.tagName.outputs.tag }}-amd64

build-and-publish-arm64:
runs-on: arm64-ubuntu-22
steps:
- name: Get tag name
uses: olegtarasov/[email protected]
id: tagName
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: kubetail/echoserver:${{ steps.tagName.outputs.tag }}-arm64

create-and-publish-manifest:
runs-on: ubuntu-latest
needs: [build-and-publish-amd64, build-and-publish-arm64]
steps:
- name: Get tag name
uses: olegtarasov/[email protected]
id: tagName
- name: 'Setup jq'
uses: dcarbone/install-jq-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create and push manifest
run: |
docker buildx imagetools create -t kubetail/echoserver:${{ steps.tagName.outputs.tag }} \
kubetail/echoserver:${{ steps.tagName.outputs.tag }}-amd64 \
kubetail/echoserver:${{ steps.tagName.outputs.tag }}-arm64
- name: Fetch docker token
run: |
TOKEN=$(curl -X POST "https://hub.docker.com/v2/users/login" -H "Content-Type: application/json" -d '{"username": "${{ secrets.DOCKERHUB_USERNAME }}", "password": "${{ secrets.DOCKERHUB_TOKEN }}"}' | jq -r '.token')
echo "TOKEN=$TOKEN" >> $GITHUB_ENV
- name: Delete extra arch manifests
run: |
declare -a archs=("amd64" "arm64")
for arch in "${archs[@]}"
do
RESPONSE=$(curl -s -w "%{http_code}" \
-X DELETE \
-H "Authorization: Bearer $TOKEN" \
"https://hub.docker.com/v2/repositories/kubetail/echoserver/tags/${{ steps.tagName.outputs.tag }}-$arch")
if [ "$RESPONSE" -ne 204 ]; then
echo "DELETE for $arch failed with status $RESPONSE"
exit 1
fi
done
29 changes: 12 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

#FROM nginx:1.24.0-alpine3.17-slim
#FROM nginx:1.26.1-alpine3.19-slim
#RUN apk add --no-cache nginx-mod-http-lua
#FROM fabiocicerchia/nginx-lua:1.27.0-alpine3.20.1
#RUN rm -rf /etc/nginx/conf.d
#FROM nginx:1.26.1-alpine3.19-slim
#FROM nginx:1.27.0-alpine3.19
#RUN apk update && apk add --no-cache nginx-plus-module-lua
#ADD nginx.conf /etc/nginx/nginx.conf
#ADD README.md README.md
FROM alpine:3.20.1

FROM alpine:3.17.8

RUN apk add --no-cache nginx-mod-http-lua
RUN apk update
RUN apk add --no-cache openssl nginx-mod-http-lua lua-dev luarocks
RUN luarocks-5.1 install lua-resty-template

# Create folder for PID file
RUN mkdir -p /run/nginx

# Add custom nginx conf
COPY ./nginx.conf /etc/nginx/nginx.conf
# Add files
COPY entrypoint.sh /usr/local/bin/
COPY nginx.conf /etc/nginx/nginx.conf

EXPOSE 8080
EXPOSE 8443

ENTRYPOINT ["nginx"]
CMD ["-c", "/etc/nginx/nginx.conf"]
ENTRYPOINT ["entrypoint.sh"]
CMD ["nginx", "-c", "/etc/nginx/nginx.conf"]
51 changes: 46 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
# Echoserver

This is a simple server that responds with the http headers it received.
Image versions >= 1.4 removes the redirect introduced in 1.3.
Image versions >= 1.3 redirect requests on :80 with `X-Forwarded-Proto: http` to :443.
Image versions > 1.0 run an nginx server, and implement the echoserver using lua in the nginx config.
Image versions <= 1.0 run a python http server instead of nginx, and don't redirect any requests.
This is a fork of the enigmatic `k8s.gcr.io/echoserver` image, designed to run on amd64 and arm64 architecture.

## Introduction

The `k8s.gcr.io/echoserver` image is very useful but unfortunately it's not available for [arm64 architecture](https://github.com/kubernetes-retired/contrib/issues/2991). In addition, we couldn't find the source code online so we dug into the image files, copied the nginx config and created this fork to make an `echoserver` that's more transparent and available across architectures.

Echoserver, uses a lua script running inside Nginx to respond to HTTP requests on port 8080 and HTTPS requests on port 8443. On start-up, it creates a self-signed certificate for the ssl listener.

## Install

Here's a manifest you can use to run an echoserver deployment on kubernetes:

```yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: echoserver
namespace: default
labels:
app.kubernetes.io/name: echoserver
spec:
selector:
matchLabels:
app.kubernetes.io/name: echoserver
replicas: 3
revisionHistoryLimit: 5
template:
metadata:
labels:
app.kubernetes.io/name: echoserver
spec:
containers:
- name: echoserver
image: kubetail/echoserver:0.0.1
ports:
- name: http
containerPort: 8080
- name: https
containerPort: 8443
```
## Build
```console
docker build -t echoserver:latest .
```
19 changes: 19 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

CERT_DIR=/certs
CERT_FILE=$CERT_DIR/certificate.crt
KEY_FILE=$CERT_DIR/privateKey.key

# Check if certificate and key files exist, if not, create them
if [ ! -f "$CERT_FILE" ] || [ ! -f "$KEY_FILE" ]; then
#echo "Generating self-signed cert"
#echo "Generating a 2048 bit RSA private key"
mkdir -p $CERT_DIR
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout $KEY_FILE -out $CERT_FILE -subj "/C=US/ST=State/L=City/O=Organization/OU=OrgUnit/CN=localhost" -verbose
#echo "writing new private key to '${KEY_FILE}'"
fi

# Start your application here, e.g., for a Node.js app
# node /path/to/your/app.js
echo "Starting nginx"
exec "$@"
12 changes: 10 additions & 2 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ load_module /usr/lib/nginx/modules/ngx_http_lua_module.so;

pcre_jit on;

daemon off;
error_log stderr;

events {
worker_connections 1024;
}
Expand All @@ -14,14 +17,16 @@ env POD_NAMESPACE;
env POD_IP;

http {
access_log /dev/stdout;

default_type 'text/plain';
# maximum allowed size of the client request body. By default this is 1m.
# Request with bigger bodies nginx will return error code 413.
# http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
client_max_body_size 10m;

init_by_lua_block {
local template = require("template")
local template = require("resty.template")
-- template syntax documented here:
-- https://github.com/bungle/lua-resty-template/blob/master/README.md
tmpl = template.compile([[
Expand Down Expand Up @@ -66,7 +71,9 @@ Request Body:
# basically instructs to create an individual listening socket for each worker process (using the SO_REUSEPORT
# socket option), allowing a kernel to distribute incoming connections between worker processes.
listen 8080 default_server reuseport;
listen 8443 default_server ssl http2 reuseport;
listen 8443 default_server ssl reuseport;

http2 on;

ssl_certificate /certs/certificate.crt;
ssl_certificate_key /certs/privateKey.key;
Expand All @@ -91,3 +98,4 @@ Request Body:
}
}
}

0 comments on commit af2696e

Please sign in to comment.