|
| 1 | +name: Docker Images CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + # Publish semver tags as releases. |
| 7 | + tags: ["v*.*.*"] |
| 8 | + |
| 9 | +env: |
| 10 | + REGISTRY: ghcr.io |
| 11 | + ORG: trypromptly |
| 12 | + IMAGE_NAME_API: "llmstack-api" |
| 13 | + IMAGE_NAME_NGINX: "llmstack-nginx" |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + packages: write |
| 22 | + # This is used to complete the identity challenge |
| 23 | + # with sigstore/fulcio when running outside of PRs. |
| 24 | + id-token: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v3 |
| 29 | + |
| 30 | + # Install the cosign tool except on PR |
| 31 | + # https://github.com/sigstore/cosign-installer |
| 32 | + - name: Install cosign |
| 33 | + if: github.event_name != 'pull_request' |
| 34 | + |
| 35 | + with: |
| 36 | + cosign-release: "v2.1.1" |
| 37 | + |
| 38 | + # Setup QEMU for cross compilation |
| 39 | + - name: Set up QEMU |
| 40 | + uses: docker/setup-qemu-action@v2 |
| 41 | + |
| 42 | + # Setup Docker Buildx |
| 43 | + - name: Set up Docker Buildx |
| 44 | + uses: docker/setup-buildx-action@v2 |
| 45 | + |
| 46 | + # Login against a Docker registry except on PR |
| 47 | + # https://github.com/docker/login-action |
| 48 | + - name: Log into registry ${{ env.REGISTRY }} |
| 49 | + if: github.event_name != 'pull_request' |
| 50 | + |
| 51 | + with: |
| 52 | + registry: ${{ env.REGISTRY }} |
| 53 | + username: ${{ github.actor }} |
| 54 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + # Extract metadata (tags, labels) for Docker |
| 57 | + # https://github.com/docker/metadata-action |
| 58 | + - name: Extract Docker metadata for API |
| 59 | + id: meta-api |
| 60 | + uses: docker/metadata-action@v4 |
| 61 | + with: |
| 62 | + images: ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE_NAME_API }} |
| 63 | + tags: | |
| 64 | + type=raw,value=latest,event=push,enabled={{is_default_branch}} |
| 65 | + type=semver,enabled={{starts_with(github.ref, 'refs/tags/v')}},pattern={{version}} |
| 66 | +
|
| 67 | + - name: Extract Docker metadata for nginx |
| 68 | + id: meta-nginx |
| 69 | + uses: docker/metadata-action@v4 |
| 70 | + with: |
| 71 | + images: ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE_NAME_NGINX }} |
| 72 | + tags: | |
| 73 | + type=raw,value=latest,event=push,enabled={{is_default_branch}} |
| 74 | + type=semver,enabled={{starts_with(github.ref, 'refs/tags/v')}},pattern={{version}} |
| 75 | +
|
| 76 | + # Build client |
| 77 | + - name: Build client |
| 78 | + run: | |
| 79 | + cd client |
| 80 | + npm install |
| 81 | + npm run build |
| 82 | +
|
| 83 | + # Build and push Docker image with Buildx (don't push on PR) |
| 84 | + # https://github.com/docker/build-push-action |
| 85 | + - name: Build and push LLMStack API Docker image |
| 86 | + id: build-and-push-api |
| 87 | + uses: docker/build-push-action@v4 |
| 88 | + with: |
| 89 | + context: . |
| 90 | + push: ${{ github.event_name != 'pull_request' }} |
| 91 | + tags: ${{ steps.meta-api.outputs.tags }} |
| 92 | + labels: ${{ steps.meta-api.outputs.labels }} |
| 93 | + cache-from: type=gha |
| 94 | + cache-to: type=gha,mode=max |
| 95 | + file: Dockerfile |
| 96 | + platforms: linux/amd64,linux/arm64 |
| 97 | + |
| 98 | + - name: Build and push LLMStack nginx Docker image |
| 99 | + id: build-and-push-nginx |
| 100 | + uses: docker/build-push-action@v4 |
| 101 | + with: |
| 102 | + context: . |
| 103 | + push: ${{ github.event_name != 'pull_request' }} |
| 104 | + tags: ${{ steps.meta-nginx.outputs.tags }} |
| 105 | + labels: ${{ steps.meta-nginx.outputs.labels }} |
| 106 | + cache-from: type=gha |
| 107 | + cache-to: type=gha,mode=max |
| 108 | + file: Dockerfile.nginx |
| 109 | + platforms: linux/amd64,linux/arm64 |
| 110 | + build-args: REGISTRY=${{ env.REGISTRY }}/${{ env.ORG }}/ |
| 111 | + |
| 112 | + - name: Sign the published LLMStack API Docker image |
| 113 | + if: ${{ github.event_name != 'pull_request' }} |
| 114 | + env: |
| 115 | + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable |
| 116 | + TAGS: ${{ steps.meta-api.outputs.tags }} |
| 117 | + DIGEST: ${{ steps.build-and-push-api.outputs.digest }} |
| 118 | + # This step uses the identity token to provision an ephemeral certificate |
| 119 | + # against the sigstore community Fulcio instance. |
| 120 | + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} |
| 121 | + |
| 122 | + - name: Sign the published LLMStack nginx Docker image |
| 123 | + if: ${{ github.event_name != 'pull_request' }} |
| 124 | + env: |
| 125 | + TAGS: ${{ steps.meta-nginx.outputs.tags }} |
| 126 | + DIGEST: ${{ steps.build-and-push-nginx.outputs.digest }} |
| 127 | + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} |
0 commit comments