|
10 | 10 | - main |
11 | 11 | workflow_dispatch: |
12 | 12 |
|
| 13 | +env: |
| 14 | + REGISTRY: ghcr.io |
| 15 | + |
13 | 16 | jobs: |
14 | 17 | test: |
15 | 18 | runs-on: ubuntu-latest |
|
66 | 69 |
|
67 | 70 | - name: Run tests (including property tests) |
68 | 71 | run: mix test --include test |
| 72 | + |
| 73 | + docker-build: |
| 74 | + runs-on: ubuntu-latest |
| 75 | + permissions: |
| 76 | + contents: read |
| 77 | + |
| 78 | + steps: |
| 79 | + - name: Checkout repository |
| 80 | + uses: actions/checkout@v4 |
| 81 | + |
| 82 | + - name: Set up Docker Buildx |
| 83 | + uses: docker/setup-buildx-action@v3 |
| 84 | + |
| 85 | + - name: Extract metadata |
| 86 | + id: meta |
| 87 | + uses: docker/metadata-action@v5 |
| 88 | + with: |
| 89 | + images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/cascade |
| 90 | + tags: | |
| 91 | + type=ref,event=branch |
| 92 | + type=ref,event=pr |
| 93 | + type=sha,prefix={{branch}}- |
| 94 | + type=raw,value=latest,enable={{is_default_branch}} |
| 95 | +
|
| 96 | + - name: Build Docker image (no push) |
| 97 | + uses: docker/build-push-action@v5 |
| 98 | + with: |
| 99 | + context: . |
| 100 | + file: ./Dockerfile |
| 101 | + push: false |
| 102 | + tags: ${{ steps.meta.outputs.tags }} |
| 103 | + labels: ${{ steps.meta.outputs.labels }} |
| 104 | + cache-from: type=gha |
| 105 | + cache-to: type=gha,mode=max |
| 106 | + outputs: type=docker,dest=/tmp/cascade-image.tar |
| 107 | + |
| 108 | + - name: Upload Docker image artifact |
| 109 | + uses: actions/upload-artifact@v4 |
| 110 | + with: |
| 111 | + name: cascade-docker-image |
| 112 | + path: /tmp/cascade-image.tar |
| 113 | + retention-days: 1 |
| 114 | + |
| 115 | + docker-push: |
| 116 | + runs-on: ubuntu-latest |
| 117 | + needs: [test, docker-build] |
| 118 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') |
| 119 | + permissions: |
| 120 | + contents: read |
| 121 | + packages: write |
| 122 | + |
| 123 | + steps: |
| 124 | + - name: Checkout repository |
| 125 | + uses: actions/checkout@v4 |
| 126 | + |
| 127 | + - name: Download Docker image artifact |
| 128 | + uses: actions/download-artifact@v4 |
| 129 | + with: |
| 130 | + name: cascade-docker-image |
| 131 | + path: /tmp |
| 132 | + |
| 133 | + - name: Load Docker image |
| 134 | + run: docker load --input /tmp/cascade-image.tar |
| 135 | + |
| 136 | + - name: Log in to Container Registry |
| 137 | + uses: docker/login-action@v3 |
| 138 | + with: |
| 139 | + registry: ${{ env.REGISTRY }} |
| 140 | + username: ${{ github.actor }} |
| 141 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 142 | + |
| 143 | + - name: Extract metadata |
| 144 | + id: meta |
| 145 | + uses: docker/metadata-action@v5 |
| 146 | + with: |
| 147 | + images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/cascade |
| 148 | + tags: | |
| 149 | + type=ref,event=branch |
| 150 | + type=sha,prefix={{branch}}- |
| 151 | + type=raw,value=latest,enable={{is_default_branch}} |
| 152 | +
|
| 153 | + - name: Push Docker image to registry |
| 154 | + run: | |
| 155 | + for tag in $(echo "${{ steps.meta.outputs.tags }}" | tr ',' ' '); do |
| 156 | + docker tag $(docker images -q | head -n1) $tag |
| 157 | + docker push $tag |
| 158 | + done |
0 commit comments