diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4cd7c0..a779cd1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,11 +22,3 @@ jobs: - run: npm run build env: AUTH_SECRET: ci-build-secret-at-least-32-characters - - docker: - name: docker-build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Build production image - run: docker build -t rfid-database:ci . diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..5448d15 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,60 @@ +name: Docker + +on: + push: + branches: [main] + tags: ["v*"] + pull_request: + branches: [main] + +env: + REGISTRY: ghcr.io + # GHCR requires lowercase image names + IMAGE_NAME: ghcr.io/chewbaccalakis/rfid-database + +jobs: + build-and-push: + name: build-and-push + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + attestations: write + id-token: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=sha,prefix=sha-,format=short + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + 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 diff --git a/README.md b/README.md index a2f6765..01e0397 100644 --- a/README.md +++ b/README.md @@ -117,10 +117,26 @@ npm run typecheck npm run build ``` -GitHub Actions runs on every pull request and push to `main`: +GitHub Actions on every pull request and push to `main`: 1. **lint / typecheck / test / Next.js build** -2. **`docker build`** — catches Dockerfile parse/build failures (the class of break that conflict markers previously caused) +2. **Docker image** — build on PRs; on `main` (and `v*` tags) push to GHCR: + `ghcr.io/chewbaccalakis/rfid-database` + +### Pull the published image + +```bash +docker pull ghcr.io/chewbaccalakis/rfid-database:latest +# or a specific commit: ghcr.io/chewbaccalakis/rfid-database:sha- +``` + +If the package is private, authenticate first: + +```bash +echo $GITHUB_TOKEN | docker login ghcr.io -u USERNAME --password-stdin +``` + +Or in Compose, set `image: ghcr.io/chewbaccalakis/rfid-database:latest` and comment out `build:`. ## Docker diff --git a/docker-compose.yml b/docker-compose.yml index 31bc601..5f8fc0f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,13 @@ services: rfid-database: + # Local build (default): build: context: . dockerfile: Dockerfile image: rfid-database:local + # Or pull from GHCR instead of building: + # image: ghcr.io/chewbaccalakis/rfid-database:latest + # pull_policy: always container_name: rfid-database restart: unless-stopped ports: