diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml new file mode 100644 index 000000000..22e496372 --- /dev/null +++ b/.github/workflows/container.yml @@ -0,0 +1,81 @@ +name: Build blog in container + +on: + push: + branches: [ "main" ] + 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 repository + uses: actions/checkout@v4 + + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@v3.4.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.2.0 + + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3.1.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5.5.1 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Setup Hugo + run: | + LATEST_HUGO_VERSION=$(grep github.com/gohugoio/hugo go.mod | awk '{print $NF}' | sed 's/^v//') + HUGO_DOWNLOAD_URL="https://github.com/gohugoio/hugo/releases/download/v${LATEST_HUGO_VERSION}/hugo_extended_${LATEST_HUGO_VERSION}_linux-amd64.tar.gz" + curl -sL --retry 5 "$HUGO_DOWNLOAD_URL" | tar xvzf - hugo + ./hugo version + + - name: Build with Hugo + env: + HUGO_ENVIRONMENT: production + HUGO_ENV: production + run: ./hugo --gc --minify --baseURL "${{ steps.pages.outputs.base_url }}/" + + - name: Fix RSS feed + run: | + mkdir -vp public/feed + cp public/index.xml public/feed/index.xml + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v5.3.0 + with: + context: . + 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 + + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..964821b38 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM docker.io/library/busybox:1.36.1 +RUN adduser -D static +USER static +WORKDIR /home/static +COPY ./public/ /home/static +CMD ["busybox", "httpd", "-f", "-v", "-p", "3000"] \ No newline at end of file