From c39b9a2d0e12957fd7094ae598bbeb28314c0bc9 Mon Sep 17 00:00:00 2001 From: v1xingyue Date: Sat, 7 Dec 2024 12:58:10 +0800 Subject: [PATCH 1/4] github image cicd --- .github/workflows/image.yaml | 63 ++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/image.yaml diff --git a/.github/workflows/image.yaml b/.github/workflows/image.yaml new file mode 100644 index 0000000000..93053c5cee --- /dev/null +++ b/.github/workflows/image.yaml @@ -0,0 +1,63 @@ +# +name: Create and publish a Docker image + +# Configures this workflow to run every time a change is pushed to the branch called `release`. +on: + workflow_dispatch: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + attestations: write + id-token: write + # + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + id: push + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)." + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true + From f99000e6b0b2f7ae9f50af6f83b3c19644656f3d Mon Sep 17 00:00:00 2001 From: v1xingyue Date: Sat, 7 Dec 2024 12:59:32 +0800 Subject: [PATCH 2/4] cicd when release --- .github/workflows/image.yaml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/image.yaml b/.github/workflows/image.yaml index 93053c5cee..ddd543b0b9 100644 --- a/.github/workflows/image.yaml +++ b/.github/workflows/image.yaml @@ -3,11 +3,9 @@ name: Create and publish a Docker image # Configures this workflow to run every time a change is pushed to the branch called `release`. on: - workflow_dispatch: - push: - branches: ["main"] - pull_request: - branches: ["main"] + release: + types: [created] + workflow_dispatch: # Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. env: From 16f04998963120a5fe17cdfe25949b164cf5b7a8 Mon Sep 17 00:00:00 2001 From: v1xingyue Date: Sun, 8 Dec 2024 16:53:56 +0800 Subject: [PATCH 3/4] pnpm build have bugs with Dockerfile --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 732d8ad6cf..8006b83157 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "eliza", "scripts": { "preinstall": "npx only-allow pnpm", - "build": "turbo run build --filter=!eliza-docs", + "build": "turbo run build", "start": "pnpm --filter \"@ai16z/agent\" start --isRoot", "start:client": "pnpm --dir client start --isRoot", "start:debug": "cross-env NODE_ENV=development VERBOSE=true DEBUG=eliza:* pnpm --filter \"@ai16z/agent\" start --isRoot", From 0bb2860a44409bf848e1fe965dee80dee098148c Mon Sep 17 00:00:00 2001 From: v1xingyue Date: Wed, 11 Dec 2024 10:34:14 +0800 Subject: [PATCH 4/4] modify build-docker --- Dockerfile | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index a16b33ac0c..d97ed212cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ COPY characters ./characters # Install dependencies and build the project RUN pnpm install \ - && pnpm build \ + && pnpm build-docker \ && pnpm prune --prod # Create a new stage for the final image diff --git a/package.json b/package.json index 8006b83157..ebbafb73a8 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,12 @@ "name": "eliza", "scripts": { "preinstall": "npx only-allow pnpm", - "build": "turbo run build", + "build": "turbo run build --filter=!eliza-docs", + "build-docker": "turbo run build", "start": "pnpm --filter \"@ai16z/agent\" start --isRoot", "start:client": "pnpm --dir client start --isRoot", "start:debug": "cross-env NODE_ENV=development VERBOSE=true DEBUG=eliza:* pnpm --filter \"@ai16z/agent\" start --isRoot", "dev": "bash ./scripts/dev.sh", - "dev:build": "turbo run build --filter=!eliza-docs", "lint": "bash ./scripts/lint.sh", "prettier-check": "npx prettier --check .", "prettier": "npx prettier --write .",