From fcb70f44f9ff1ddbfc5e36ec2957e8a2a33a8505 Mon Sep 17 00:00:00 2001 From: Mohammad Hemmati Date: Mon, 3 Aug 2026 10:03:06 +0330 Subject: [PATCH] add docker --- .dockerignore | 6 ++++ .github/workflows/ghcr.yml | 58 ++++++++++++++++++++++++++++++++++++++ Dockerfile | 4 +++ 3 files changed, 68 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/ghcr.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a0666e9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +.github +Dockerfile +docker-compose.yml +.env +*.log diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml new file mode 100644 index 0000000..42318f6 --- /dev/null +++ b/.github/workflows/ghcr.yml @@ -0,0 +1,58 @@ +name: Build and publish Docker image to GHCR + +on: + push: + branches: + - dockerize-ghcr + pull_request: + branches: + - dockerize-ghcr + workflow_dispatch: + +permissions: + contents: read + packages: write + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Compute lowercase image name + id: vars + run: | + # Ensure the image name (registry/owner/repo) is lowercase because container registries require lowercase names + image="ghcr.io/${GITHUB_REPOSITORY}" + image_lc=$(echo "$image" | tr '[:upper:]' '[:lower:]') + echo "image=$image_lc" >> $GITHUB_OUTPUT + + - name: Log in to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: | + ${{ steps.vars.outputs.image }}:latest + ${{ steps.vars.outputs.image }}:${{ github.sha }} + + - name: Fallback note for GHCR PAT + if: failure() && github.event_name != 'pull_request' + run: | + echo "If pushing failed due to GITHUB_TOKEN restrictions, create a PAT with write:packages and set it as GHCR_PAT, then update the workflow to use secrets.GHCR_PAT for docker/login-action." diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0f2981b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM busybox:1.37.0-musl +COPY public/ /public/ +EXPOSE 8080 +CMD ["httpd", "-f", "-p", "8080", "-h", "/public"]