diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..af787f5 --- /dev/null +++ b/.github/workflows/release.yml @@ -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/get-tag@2.1.3 + 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/get-tag@2.1.3 + 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/get-tag@2.1.3 + 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 diff --git a/Dockerfile b/Dockerfile index 69e6a5e..fb583a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index 84349a2..e9ce2b8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ # 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 kubernetes echoserver + +## Build + +```console +docker build -t echoserver:latest . +docker run -it --rm -p 8080:8080 echoserver:latest +``` diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..24d72e7 --- /dev/null +++ b/entrypoint.sh @@ -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 "$@" diff --git a/nginx.conf b/nginx.conf index 1c1aa67..84eba7a 100644 --- a/nginx.conf +++ b/nginx.conf @@ -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; } @@ -14,6 +17,8 @@ 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. @@ -21,7 +26,7 @@ http { 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([[ @@ -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; @@ -91,3 +98,4 @@ Request Body: } } } +