From a4123114018ec7e1f634a0e6b70bd030a6ad085d Mon Sep 17 00:00:00 2001 From: Shibi J M <6216943+shibijm@users.noreply.github.com> Date: Tue, 12 Sep 2023 07:33:59 +0530 Subject: [PATCH] Dockerisation --- .dockerignore | 4 ++ .github/workflows/build-and-release.yml | 19 --------- .github/workflows/release.yml | 56 +++++++++++++++++++++++++ Dockerfile | 12 ++++++ 4 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 .dockerignore delete mode 100644 .github/workflows/build-and-release.yml create mode 100644 .github/workflows/release.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1bd757a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.dockerignore +.git +.github +Dockerfile diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml deleted file mode 100644 index a66d771..0000000 --- a/.github/workflows/build-and-release.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Build and release -run-name: Build and release ${{ inputs.version || github.ref_name }} -on: - push: - tags: - - v* - workflow_dispatch: - inputs: - version: - required: true - type: string - description: Version (vX.X.X.X) -jobs: - build-python-release: - uses: shibijm/gh-actions-workflows/.github/workflows/build-python-release-preset-1.yml@master - with: - version: ${{ inputs.version || github.ref_name }} - permissions: - contents: write diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..939c409 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: Release +run-name: Release ${{ inputs.version || github.ref_name }} +on: + push: + tags: + - v* + workflow_dispatch: + inputs: + version: + required: true + type: string + description: Version (vX.X.X) +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + env: + VERSION: ${{ inputs.version || github.ref_name }} + RELEASE_ZIP_FILENAME: ${{ github.event.repository.name }}-${{ inputs.version || github.ref_name }}.zip + DOCKER_IMAGE_NAME: ghcr.io/${{ github.actor }}/${{ github.event.repository.name }} + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Create release ZIP file + run: zip -r $RELEASE_ZIP_FILENAME . -x /.git/* -x /.github/* -x /.dockerignore -x /Dockerfile + - name: Delete existing GitHub release, if any + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + run: gh release delete $VERSION --cleanup-tag --yes || true + - name: Release on GitHub + uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 + with: + tag_name: ${{ env.VERSION }} + generate_release_notes: true + files: ${{ env.RELEASE_ZIP_FILENAME }} + - name: Delete release ZIP file + run: rm $RELEASE_ZIP_FILENAME + - name: Sign into GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + provenance: false + tags: ${{ env.DOCKER_IMAGE_NAME }}:${{ env.VERSION }},${{ env.DOCKER_IMAGE_NAME }}:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8343a0a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.10-alpine +ARG USERNAME=app +ARG USER_UID=10000 +ARG USER_GID=$USER_UID +RUN addgroup -g $USER_GID $USERNAME && adduser -u $USER_UID -G $USERNAME -D $USERNAME +USER $USERNAME +WORKDIR /app +COPY --chown=$USERNAME:$USERNAME requirements.txt . +RUN pip install -r requirements.txt --no-cache-dir +COPY --chown=$USERNAME:$USERNAME . . +CMD ["python", "main.py"] +EXPOSE 22334