From 417f079b0cf2e51d894d6b31d7e7d171d62efdaf Mon Sep 17 00:00:00 2001 From: "Seele.Clover" <37256067+seeleclover@users.noreply.github.com> Date: Sun, 8 Oct 2023 22:52:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=80=9A=E8=BF=87=20Dock?= =?UTF-8?q?er=20=E9=83=A8=E7=BD=B2=E9=A1=B9=E7=9B=AE=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 2 ++ .vercelignore | 4 ++++ Dockerfile | 14 ++++++++++++++ __init__.py | 16 ++++++++++++++++ requirements.txt | 2 +- 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 .vercelignore create mode 100644 Dockerfile create mode 100644 __init__.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..19bb1e1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.* +*.md diff --git a/.vercelignore b/.vercelignore new file mode 100644 index 0000000..2be948e --- /dev/null +++ b/.vercelignore @@ -0,0 +1,4 @@ +.* +*.md +__init__.py +Dockerfile \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ecd37e4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM python:3-alpine + +LABEL name="python_github_calendar_api" \ + repository="https://github.com/Zfour/python_github_calendar_api" \ + contrubutors="Zfour, ShengQiBaoZao, seeleclover" + +ENV TZ=Asia/Shanghai + +WORKDIR /usr/src/app + +COPY . . +RUN pip install --no-cache-dir -r requirements.txt + +CMD [ "python", "-u", "__init__.py" ] diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..2b6afe3 --- /dev/null +++ b/__init__.py @@ -0,0 +1,16 @@ +# -*- coding: UTF-8 -*- +from http.server import HTTPServer +from api.index import handler +import logging + +logging.basicConfig( + datefmt = '%d/%b/%Y %H:%M:%S', + format = '[%(asctime)s] "%(levelname)s: %(message)s" -', + level=logging.INFO +) + +if __name__ == '__main__': + host = ('0.0.0.0', 80) + server = HTTPServer(host, handler) + logging.info("Starting server, listen at http://%s:%s" % host) + server.serve_forever() diff --git a/requirements.txt b/requirements.txt index 570b153..e1bc62c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ certifi==2020.12.5 chardet==4.0.0 idna==2.10 requests==2.25.1 -urllib3==1.26.2 +urllib3==1.26.17 From 4003a637fa3e43bdc958fd4c3e8559a3c536520c Mon Sep 17 00:00:00 2001 From: "Seele.Clover" <37256067+seeleclover@users.noreply.github.com> Date: Mon, 9 Oct 2023 00:41:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A9=E7=94=A8=20GitHub=20Action=20?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8C=96=E6=9E=84=E5=BB=BA=20Docker=20?= =?UTF-8?q?=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image-ci.yml | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/docker-image-ci.yml diff --git a/.github/workflows/docker-image-ci.yml b/.github/workflows/docker-image-ci.yml new file mode 100644 index 0000000..97d2bc4 --- /dev/null +++ b/.github/workflows/docker-image-ci.yml @@ -0,0 +1,62 @@ +name: Docker Image CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + workflow_dispatch: + inputs: + tags: + description: 'Manual Build' + required: false + +jobs: + build-and-push: + runs-on: ubuntu-latest + + env: + IMAGE_NAME: python_github_calendar_api + + steps: + - + name: Checkout Code + uses: actions/checkout@v4 + + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + + - + name: Get current datetime for Image Tag + id: datetime + run: echo "::set-output name=tag::$(TZ='Asia/Shanghai' date +'%Y%m%d_%H%M%S')" + + - + name: Build and Push Image + uses: docker/build-push-action@v5 + with: + context: . + platforms: | + linux/386 + linux/amd64 + linux/arm/v6 + linux/arm/v7 + linux/arm64/v8 + linux/ppc64le + linux/s390x + push: true + tags: | + ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.datetime.outputs.tag }} + ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest