odin-detector/odin-data

View on GitHub
.github/workflows/container.yml

Summary

Maintainability
Test Coverage
name: Container CI

# Only tags are pushed to the registry because of rules in the steps
on:
  push:
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

    env:
      TAG: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0 # All history

      - name: Cache Docker layers
        uses: actions/cache@v2
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-

      - name: Log in to GitHub Docker Registry
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1

      - name: Build image
        uses: docker/build-push-action@v4
        with:
          context: .
          file: Dockerfile
          target: runtime
          push: false
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache

      - name: Create tags for developer image
        id: meta-developer
        uses: docker/metadata-action@v5
        with:
          images: ghcr.io/${{ github.repository }}-developer
          tags: |
            type=ref,event=tag
            type=raw,value=latest

      - name: Push developer image
        if: github.ref_type == 'tag'
        uses: docker/build-push-action@v4
        with:
          context: .
          file: Dockerfile
          target: developer
          tags: ${{ steps.meta-developer.outputs.tags }}
          labels: ${{ steps.meta-developer.outputs.labels }}
          push: ${{ github.event_name != 'pull_request' }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache

      - name: Create tags for build image
        id: meta-build
        uses: docker/metadata-action@v5
        with:
          images: ghcr.io/${{ github.repository }}-build
          tags: |
            type=ref,event=tag
            type=raw,value=latest

      - name: Push build image
        if: github.ref_type == 'tag'
        uses: docker/build-push-action@v4
        with:
          context: .
          file: Dockerfile
          target: build
          tags: ${{ steps.meta-build.outputs.tags }}
          labels: ${{ steps.meta-build.outputs.labels }}
          push: ${{ github.event_name != 'pull_request' }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache

      - name: Create tags for runtime image
        id: meta-runtime
        uses: docker/metadata-action@v5
        with:
          images: ghcr.io/${{ github.repository }}-runtime
          tags: |
            type=ref,event=tag
            type=raw,value=latest

      - name: Push runtime image
        if: github.ref_type == 'tag'
        uses: docker/build-push-action@v4
        with:
          context: .
          file: Dockerfile
          target: runtime
          tags: ${{ steps.meta-runtime.outputs.tags }}
          labels: ${{ steps.meta-runtime.outputs.labels }}
          push: ${{ github.event_name != 'pull_request' }}
          cache-from: type=local,src=/tmp/.buildx-cache
          cache-to: type=local,dest=/tmp/.buildx-cache