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/.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 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