diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..7b8a2aa --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,63 @@ +name: Main + +on: + push: + branches: [main] + pull_request: + branches: [main] + +env: + REGISTRY: gitea.lucids-cove.duckdns.org + OWNER: wkc + IMAGE_NAME: no-twitter-bot-stats + +jobs: + build-and-push-docker-image: + runs-on: ubuntu-24.04 + strategy: + matrix: + node-version: [20.x] + steps: + - name: "Base requirements" + run: | + # packages + apk update && apk add --no-cache git docker docker-compose nodejs gpg openssh npm ansible + # ansible collections + ansible-galaxy collection install community.general --force + ansible-galaxy collection install ansible.posix --force + - uses: actions/checkout@v4 + - name: Enable Corepack + run: npm install -g corepack && corepack enable + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ env.OWNER }} + password: ${{ secrets.TOKEN }} + - name: Docker Hub Login + run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v2 + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.IMAGE_NAME }} + - name: Build and Push Versioned Docker Image + id: build-and-push + uses: docker/build-push-action@v4 + if: ${{ github.ref != 'refs/heads/main' }} + with: + context: . + push: ${{ !github.event.pull_request.head.repo.fork }} + tags: ${{ steps.meta.outputs.tags }} + - name: Build and Push Latest Docker Image + id: build-and-push-latest + uses: docker/build-push-action@v4 + if: ${{ github.ref == 'refs/heads/main' }} + with: + context: . + push: true + tags: ${{ env.REGISTRY }}/${{ env.OWNER }}/${{ env.IMAGE_NAME }}:latest diff --git a/Dockerfile b/Dockerfile index 2e33410..53bb277 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,12 @@ FROM node:20-alpine AS base +# Enable Corepack +RUN corepack enable + +# Set Yarn to the latest stable version +RUN yarn set version stable + # Install dependencies only when needed FROM base AS deps # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.