|
| 1 | + |
| 2 | +name: Create and publish a Docker image |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + push: |
| 7 | + pull_request: |
| 8 | + |
| 9 | +env: |
| 10 | + REGISTRY: ghcr.io |
| 11 | + IMAGE_NAME: ${{ github.repository }} |
| 12 | + PROJECT: fastembed-js |
| 13 | + ECR_REPOSITORY: $env.PROJECT |
| 14 | + APP_NAME: $env.PROJECT |
| 15 | + |
| 16 | +jobs: |
| 17 | + |
| 18 | + build-and-push-image: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + packages: write |
| 23 | + attestations: write |
| 24 | + id-token: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Configure AWS credentials |
| 28 | + uses: meta-introspector/configure-aws-credentials@v4 |
| 29 | + with: |
| 30 | + aws-region: ${{ secrets.AWS_REGION || 'us-east-2'}} |
| 31 | + role-session-name: github-actions-${{ env.APP_NAME }} |
| 32 | + # FIXME hard coded |
| 33 | + role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID || '767503528736' }}:role/github |
| 34 | + |
| 35 | + - name: Set up Docker Buildx |
| 36 | + uses: meta-introspector/setup-buildx-action@v3.8.0 |
| 37 | + with: |
| 38 | + install: true |
| 39 | + platforms: linux/amd64,linux/arm/v7,linux/arm/v8 |
| 40 | + |
| 41 | + - name: Login to Amazon ECR |
| 42 | + id: login-ecr |
| 43 | + uses: meta-introspector/amazon-ecr-login@v1 |
| 44 | + - uses: meta-introspector/create-ecr-repository-action@v1 |
| 45 | + with: |
| 46 | + repository: $env.PROJECT |
| 47 | + |
| 48 | + - name: Set short sha |
| 49 | + id: sha_short |
| 50 | + run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 51 | + |
| 52 | + - name: Login to Docker Hub |
| 53 | + uses: meta-introspector/login-action@v3 |
| 54 | + with: |
| 55 | + username: ${{ vars.DOCKER_HUB_USERNAME }} |
| 56 | + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} |
| 57 | + |
| 58 | + - name: Checkout repository |
| 59 | + uses: meta-introspector/checkout@v4 |
| 60 | + |
| 61 | + - name: Log in to the Container registry |
| 62 | + uses: meta-introspector/login-action@v3.0.0 |
| 63 | + with: |
| 64 | + registry: ${{ env.REGISTRY }} |
| 65 | + username: ${{ github.actor }} |
| 66 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + |
| 68 | + - name: Extract metadata (tags, labels) for Docker |
| 69 | + id: meta |
| 70 | + uses: meta-introspector/metadata-action@v5.5.1 |
| 71 | + with: |
| 72 | + images: | |
| 73 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 74 | + h4ckermike/${{ env.ECR_REPOSITORY}} |
| 75 | + ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY}} |
| 76 | + |
| 77 | + - name: Build and push Docker image |
| 78 | + id: push |
| 79 | + uses: meta-introspector/build-push-action@v6.10.0 |
| 80 | + with: |
| 81 | + platforms: linux/arm64,linux/arm64/v8 |
| 82 | + context: . |
| 83 | + push: true |
| 84 | + tags: | |
| 85 | + ${{ steps.meta.outputs.tags }} |
| 86 | + labels: ${{ steps.meta.outputs.labels }} |
| 87 | + |
| 88 | + - name: Generate artifact attestation |
| 89 | + uses: meta-introspector/attest-build-provenance@local |
| 90 | + with: |
| 91 | + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} |
| 92 | + subject-digest: ${{ steps.push.outputs.digest }} |
| 93 | + push-to-registry: true |
| 94 | + |
| 95 | + - name: Make Docker image public |
| 96 | + run: | |
| 97 | + curl \ |
| 98 | + -X PATCH \ |
| 99 | + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 100 | + -H "Accept: application/vnd.github.v3+json" \ |
| 101 | + https://api.github.com/user/packages/container/${{ env.IMAGE_NAME }}/visibility \ |
| 102 | + -d '{"visibility":"public"}' |
0 commit comments