|
| 1 | +version: 2.1 |
| 2 | + |
| 3 | +orbs: |
| 4 | + gcp-cli: circleci/[email protected] |
| 5 | + |
| 6 | + utils: ethereum-optimism/[email protected] |
| 7 | + |
| 8 | +parameters: |
| 9 | + go_version: |
| 10 | + type: string |
| 11 | + default: 1.23.8 # update CI Go version here |
| 12 | + |
| 13 | +commands: |
| 14 | + gcp-oidc-authenticate: |
| 15 | + description: "Authenticate with GCP using a CircleCI OIDC token." |
| 16 | + parameters: |
| 17 | + project_id: |
| 18 | + type: env_var_name |
| 19 | + default: GCP_PROJECT_ID |
| 20 | + workload_identity_pool_id: |
| 21 | + type: env_var_name |
| 22 | + default: GCP_WIP_ID |
| 23 | + workload_identity_pool_provider_id: |
| 24 | + type: env_var_name |
| 25 | + default: GCP_WIP_PROVIDER_ID |
| 26 | + service_account_email: |
| 27 | + type: env_var_name |
| 28 | + default: GCP_SERVICE_ACCOUNT_EMAIL |
| 29 | + gcp_cred_config_file_path: |
| 30 | + type: string |
| 31 | + default: /home/circleci/gcp_cred_config.json |
| 32 | + oidc_token_file_path: |
| 33 | + type: string |
| 34 | + default: /home/circleci/oidc_token.json |
| 35 | + steps: |
| 36 | + - run: |
| 37 | + name: "Create OIDC credential configuration" |
| 38 | + command: | |
| 39 | + # Store OIDC token in temp file |
| 40 | + echo $CIRCLE_OIDC_TOKEN > << parameters.oidc_token_file_path >> |
| 41 | + # Create a credential configuration for the generated OIDC ID Token |
| 42 | + gcloud iam workload-identity-pools create-cred-config \ |
| 43 | + "projects/${<< parameters.project_id >>}/locations/global/workloadIdentityPools/${<< parameters.workload_identity_pool_id >>}/providers/${<< parameters.workload_identity_pool_provider_id >>}"\ |
| 44 | + --output-file="<< parameters.gcp_cred_config_file_path >>" \ |
| 45 | + --service-account="${<< parameters.service_account_email >>}" \ |
| 46 | + --credential-source-file=<< parameters.oidc_token_file_path >> |
| 47 | + - run: |
| 48 | + name: "Authenticate with GCP using OIDC" |
| 49 | + command: | |
| 50 | + # Configure gcloud to leverage the generated credential configuration |
| 51 | + gcloud auth login --brief --cred-file "<< parameters.gcp_cred_config_file_path >>" |
| 52 | + # Configure ADC |
| 53 | + echo "export GOOGLE_APPLICATION_CREDENTIALS='<< parameters.gcp_cred_config_file_path >>'" | tee -a "$BASH_ENV" |
| 54 | +
|
| 55 | +jobs: |
| 56 | + build-and-deploy: |
| 57 | + machine: |
| 58 | + image: ubuntu-2004:current |
| 59 | + steps: |
| 60 | + - checkout |
| 61 | + # Fetch more history for diffing |
| 62 | + - run: |
| 63 | + name: Fetch git history |
| 64 | + command: | |
| 65 | + git fetch --depth 1000 |
| 66 | +
|
| 67 | + # Build forkdiff using Docker |
| 68 | + - run: |
| 69 | + name: Build forkdiff |
| 70 | + command: | |
| 71 | + docker run --volume $(pwd):/workspace \ |
| 72 | + protolambda/forkdiff:0.1.0 \ |
| 73 | + -repo=/workspace \ |
| 74 | + -fork=/workspace/fork.yaml \ |
| 75 | + -out=/workspace/index.html |
| 76 | +
|
| 77 | + # Prepare pages directory |
| 78 | + - run: |
| 79 | + name: Build pages |
| 80 | + command: | |
| 81 | + mkdir -p /tmp/pages |
| 82 | + mv index.html /tmp/pages/index.html |
| 83 | + touch /tmp/pages/.nojekyll |
| 84 | + if [ "$CIRCLE_PROJECT_REPONAME" == "op-geth" ] && [ "$CIRCLE_PROJECT_USERNAME" == "ethereum-optimism" ]; then |
| 85 | + echo "op-geth.optimism.io" > /tmp/pages/CNAME |
| 86 | + fi |
| 87 | + - utils/github-pages-deploy: |
| 88 | + src-pages-dir: /tmp/pages |
| 89 | + docker-release: |
| 90 | + environment: |
| 91 | + DOCKER_BUILDKIT: 1 |
| 92 | + parameters: |
| 93 | + docker_name: |
| 94 | + description: Docker image name |
| 95 | + type: string |
| 96 | + default: "op-geth" |
| 97 | + docker_tags: |
| 98 | + description: Docker image tags as csv |
| 99 | + type: string |
| 100 | + registry: |
| 101 | + description: Docker registry |
| 102 | + type: string |
| 103 | + default: "us-docker.pkg.dev" |
| 104 | + repo: |
| 105 | + description: Docker repo |
| 106 | + type: string |
| 107 | + default: "oplabs-tools-artifacts/images" |
| 108 | + push_tags: |
| 109 | + description: Push release push tags |
| 110 | + type: boolean |
| 111 | + default: false |
| 112 | + machine: |
| 113 | + image: default |
| 114 | + resource_class: xlarge |
| 115 | + steps: |
| 116 | + - gcp-cli/install |
| 117 | + - gcp-oidc-authenticate |
| 118 | + - checkout |
| 119 | + - run: |
| 120 | + name: Configure Docker |
| 121 | + command: | |
| 122 | + gcloud auth configure-docker <<parameters.registry>> |
| 123 | + - run: |
| 124 | + name: Build and push |
| 125 | + command: | |
| 126 | + RAW_TAGS="<<parameters.docker_tags>>" |
| 127 | + if [ "$CIRCLE_BRANCH" = "optimism" ]; then |
| 128 | + RAW_TAGS="$RAW_TAGS,optimism" |
| 129 | + fi |
| 130 | + IMAGE_BASE="<<parameters.registry>>/<<parameters.repo>>/<<parameters.docker_name>>" |
| 131 | + DOCKER_TAGS=$(echo -ne "$RAW_TAGS" | sed "s/,/\n/g" | sed "s/[^a-zA-Z0-9\n.]/-/g" | sed -e "s|^|-t ${IMAGE_BASE}:|") |
| 132 | + docker context create buildx-build |
| 133 | + docker buildx create --use buildx-build |
| 134 | + docker buildx build --push \ |
| 135 | + $(echo -ne $DOCKER_TAGS | tr '\n' ' ') \ |
| 136 | + --platform=linux/arm64,linux/amd64 \ |
| 137 | + --build-arg VERSION=$CIRCLE_TAG \ |
| 138 | + --build-arg COMMIT=$CIRCLE_SHA \ |
| 139 | + --build-arg BUILDNUM=$CIRCLE_BUILD_NUM \ |
| 140 | + --progress plain \ |
| 141 | + -f Dockerfile . |
| 142 | + - when: |
| 143 | + condition: |
| 144 | + equal: [true, <<parameters.push_tags>>] |
| 145 | + steps: |
| 146 | + - run: |
| 147 | + name: Tag |
| 148 | + command: | |
| 149 | + ./.circleci/ci-docker-tag-op-geth-release.sh <<parameters.registry>>/<<parameters.repo>> $CIRCLE_TAG $CIRCLE_SHA1 |
| 150 | + - when: |
| 151 | + condition: |
| 152 | + equal: [optimism, << pipeline.git.branch >>] |
| 153 | + steps: |
| 154 | + - gcp-oidc-authenticate: |
| 155 | + service_account_email: GCP_SERVICE_ATTESTOR_ACCOUNT_EMAIL |
| 156 | + - run: |
| 157 | + name: Sign |
| 158 | + command: | |
| 159 | + git clone --branch v1.0.3 --depth 1 https://github.com/ethereum-optimism/binary_signer |
| 160 | + cd binary_signer/signer |
| 161 | +
|
| 162 | + IMAGE_PATH="<<parameters.registry>>/<<parameters.repo>>/<<parameters.docker_name>>:<<pipeline.git.revision>>" |
| 163 | + echo $IMAGE_PATH |
| 164 | + pip3 install -r requirements.txt |
| 165 | +
|
| 166 | + python3 ./sign_image.py --command="sign"\ |
| 167 | + --attestor-project-name="$ATTESTOR_PROJECT_NAME"\ |
| 168 | + --attestor-name="$ATTESTOR_NAME"\ |
| 169 | + --image-path="$IMAGE_PATH"\ |
| 170 | + --signer-logging-level="INFO"\ |
| 171 | + --attestor-key-id="//cloudkms.googleapis.com/v1/projects/$ATTESTOR_PROJECT_NAME/locations/global/keyRings/$ATTESTOR_NAME-key-ring/cryptoKeys/$ATTESTOR_NAME-key/cryptoKeyVersions/1" |
| 172 | +
|
| 173 | + build-geth: |
| 174 | + docker: |
| 175 | + - image: cimg/go:<<pipeline.parameters.go_version>> |
| 176 | + resource_class: xlarge |
| 177 | + steps: |
| 178 | + - checkout |
| 179 | + - run: |
| 180 | + command: go run build/ci.go install |
| 181 | + unit-test: |
| 182 | + resource_class: xlarge |
| 183 | + docker: |
| 184 | + - image: cimg/go:<<pipeline.parameters.go_version>> |
| 185 | + steps: |
| 186 | + - checkout |
| 187 | + - run: |
| 188 | + command: go run build/ci.go test |
| 189 | + lint-geth: |
| 190 | + resource_class: medium |
| 191 | + docker: |
| 192 | + - image: cimg/go:<<pipeline.parameters.go_version>> |
| 193 | + steps: |
| 194 | + - checkout |
| 195 | + - run: |
| 196 | + command: go run build/ci.go lint |
| 197 | + tidy-geth: |
| 198 | + resource_class: small |
| 199 | + docker: |
| 200 | + - image: cimg/go:<<pipeline.parameters.go_version>> |
| 201 | + steps: |
| 202 | + - checkout |
| 203 | + - run: |
| 204 | + command: go mod tidy && git diff --exit-code |
| 205 | + check-sr-diff: |
| 206 | + docker: |
| 207 | + - image: cimg/go:<<pipeline.parameters.go_version>> |
| 208 | + steps: |
| 209 | + - checkout |
| 210 | + - run: |
| 211 | + name: install dasel |
| 212 | + command: go install github.com/tomwright/dasel/v2/cmd/[email protected] |
| 213 | + - run: |
| 214 | + name: generate artifact and check diff |
| 215 | + command: | |
| 216 | + bash ./sync-superchain.sh |
| 217 | + git diff --exit-code |
| 218 | +
|
| 219 | +workflows: |
| 220 | + main: |
| 221 | + jobs: |
| 222 | + - build-geth: |
| 223 | + name: Build geth |
| 224 | + - unit-test: |
| 225 | + name: Run unit tests for geth |
| 226 | + - lint-geth: |
| 227 | + name: Run linter over geth |
| 228 | + - tidy-geth: |
| 229 | + name: Check geth go.mod file has been tidied |
| 230 | + - docker-release: |
| 231 | + name: Push to Docker |
| 232 | + docker_tags: <<pipeline.git.revision>> |
| 233 | + context: |
| 234 | + - oplabs-gcr |
| 235 | + - check-sr-diff: |
| 236 | + name: Check superchain registry bundle diff |
| 237 | + release: |
| 238 | + jobs: |
| 239 | + - hold: |
| 240 | + type: approval |
| 241 | + filters: |
| 242 | + tags: |
| 243 | + only: /^v.*/ |
| 244 | + branches: |
| 245 | + ignore: /.*/ |
| 246 | + - docker-release: |
| 247 | + name: Push to Docker (release) |
| 248 | + filters: |
| 249 | + tags: |
| 250 | + only: /^v.*/ |
| 251 | + branches: |
| 252 | + ignore: /.*/ |
| 253 | + docker_tags: <<pipeline.git.revision>>,<<pipeline.git.tag>> |
| 254 | + push_tags: true |
| 255 | + context: |
| 256 | + - oplabs-gcr-release |
| 257 | + requires: |
| 258 | + - hold |
| 259 | + |
| 260 | + merge: |
| 261 | + jobs: |
| 262 | + - build-and-deploy: |
| 263 | + context: circleci-repo-op-geth |
| 264 | + filters: |
| 265 | + branches: |
| 266 | + only: optimism |
0 commit comments