From 7386da414ff76c79dd590ad42541702140d65a66 Mon Sep 17 00:00:00 2001 From: JP Flouret Date: Tue, 19 Mar 2024 13:12:47 -0700 Subject: [PATCH] Initial commit --- .github/workflows/docker-image.yaml | 59 +++++++++++++++++++++++++++++ Dockerfile | 5 +++ README.md | 3 ++ server.py | 25 ++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 .github/workflows/docker-image.yaml create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 server.py diff --git a/.github/workflows/docker-image.yaml b/.github/workflows/docker-image.yaml new file mode 100644 index 0000000..e1a164e --- /dev/null +++ b/.github/workflows/docker-image.yaml @@ -0,0 +1,59 @@ +name: Docker Image CI + +on: + schedule: + - cron: '29 15 * * *' + push: + branches: [ "main" ] + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "main" ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@v3.3.0 + with: + cosign-release: 'v2.2.2' + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..426691a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM python:3.9.18-alpine +WORKDIR /app +COPY server.py . +expose 8080/tcp +CMD ["python", "-u", "/app/server.py"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..fc8e055 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# teapot + +A simple web server that returns http status code 418. diff --git a/server.py b/server.py new file mode 100644 index 0000000..dc75d20 --- /dev/null +++ b/server.py @@ -0,0 +1,25 @@ +from http.server import BaseHTTPRequestHandler, HTTPServer + +bindAddress = "" +serverPort = 8080 + +class MyServer(BaseHTTPRequestHandler): + def do_GET(self): + self.server_version = 'Teapot/1.0.0' + self.sys_version = 'Coffee/1.0.0' + self.send_response(418) + self.send_header("Content-type", "text/plain; charset=utf-8") + self.end_headers() + self.wfile.write(bytes("I'm a teapot.\n", "utf-8")) + +if __name__ == "__main__": + webServer = HTTPServer((bindAddress, serverPort), MyServer) + print("Server listening on %s:%s" % (bindAddress, serverPort)) + + try: + webServer.serve_forever() + except KeyboardInterrupt: + pass + + webServer.server_close() + print("Server stopped.")