diff --git a/.github/workflows/google.yml b/.github/workflows/google.yml new file mode 100644 index 00000000..3ab19274 --- /dev/null +++ b/.github/workflows/google.yml @@ -0,0 +1,116 @@ +# This workflow will build a docker container, publish it to Google Container +# Registry, and deploy it to GKE when there is a push to the "main" +# branch. +# +# To configure this workflow: +# +# 1. Enable the following Google Cloud APIs: +# +# - Artifact Registry (artifactregistry.googleapis.com) +# - Google Kubernetes Engine (container.googleapis.com) +# - IAM Credentials API (iamcredentials.googleapis.com) +# +# You can learn more about enabling APIs at +# https://support.google.com/googleapi/answer/6158841. +# +# 2. Ensure that your repository contains the necessary configuration for your +# Google Kubernetes Engine cluster, including deployment.yml, +# kustomization.yml, service.yml, etc. +# +# 3. Create and configure a Workload Identity Provider for GitHub: +# https://github.com/google-github-actions/auth#preferred-direct-workload-identity-federation. +# +# Depending on how you authenticate, you will need to grant an IAM principal +# permissions on Google Cloud: +# +# - Artifact Registry Administrator (roles/artifactregistry.admin) +# - Kubernetes Engine Developer (roles/container.developer) +# +# You can learn more about setting IAM permissions at +# https://cloud.google.com/iam/docs/manage-access-other-resources +# +# 5. Change the values in the "env" block to match your values. + +name: "Build and Deploy to GKE" +on: + push: + branches: + - '"main"' + +env: + PROJECT_ID: "my-project" # TODO: update to your Google Cloud project ID + GAR_LOCATION: "us-central1" # TODO: update to your region + GKE_CLUSTER: "cluster-1" # TODO: update to your cluster name + GKE_ZONE: "us-central1-c" # TODO: update to your cluster zone + DEPLOYMENT_NAME: "gke-test" # TODO: update to your deployment name + REPOSITORY: "samples" # TODO: update to your Artifact Registry docker repository name + IMAGE: "static-site" + WORKLOAD_IDENTITY_PROVIDER: "projects/123456789/locations/global/workloadIdentityPools/my-pool/providers/my-provider" # TODO: update to your workload identity provider + +jobs: + setup-build-publish-deploy: + name: "Setup, Build, Publish, and Deploy" + runs-on: "ubuntu-latest" + environment: "production" + + permissions: + contents: "read" + id-token: "write" + + steps: + - name: "Checkout" + uses: "actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332" # actions/checkout@v4 + + # Configure Workload Identity Federation and generate an access token. + # + # See https://github.com/google-github-actions/auth for more options, + # including authenticating via a JSON credentials file. + - id: "auth" + name: "Authenticate to Google Cloud" + uses: "google-github-actions/auth@f112390a2df9932162083945e46d439060d66ec2" # google-github-actions/auth@v2 + with: + workload_identity_provider: "${{ env.WORKLOAD_IDENTITY_PROVIDER }}" + + # Authenticate Docker to Google Cloud Artifact Registry + - name: "Docker Auth" + uses: "docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567" # docker/login-action@v3 + with: + username: "oauth2accesstoken" + password: "${{ steps.auth.outputs.auth_token }}" + registry: "${{ env.GAR_LOCATION }}-docker.pkg.dev" + + # Get the GKE credentials so we can deploy to the cluster + - name: "Set up GKE credentials" + uses: "google-github-actions/get-gke-credentials@6051de21ad50fbb1767bc93c11357a49082ad116" # google-github-actions/get-gke-credentials@v2 + with: + cluster_name: "${{ env.GKE_CLUSTER }}" + location: "${{ env.GKE_ZONE }}" + + # Build the Docker image + - name: "Build and push Docker container" + run: |- + DOCKER_TAG="${GAR_LOCATION}-docker.pkg.dev/${PROJECT_ID}/${REPOSITORY}/${IMAGE}:${GITHUB_SHA}" + + docker build \ + --tag "${DOCKER_TAG}" \ + --build-arg GITHUB_SHA="${GITHUB_SHA}" \ + --build-arg GITHUB_REF="${GITHUB_REF}" \ + . + + docker push "${DOCKER_TAG}" + + # Set up kustomize + - name: "Set up Kustomize" + run: |- + curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.4.3/kustomize_v5.4.3_linux_amd64.tar.gz + chmod u+x ./kustomize + + # Deploy the Docker image to the GKE cluster + - name: "Deploy to GKE" + run: |- + # replacing the image name in the k8s template + ./kustomize edit set image LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE:TAG=$GAR_LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE:$GITHUB_SHA + ./kustomize build . | kubectl apply -f - + kubectl rollout status deployment/$DEPLOYMENT_NAME + kubectl get services -o wide + diff --git a/package.json b/package.json index 272f3d6e..2698e9ca 100644 --- a/package.json +++ b/package.json @@ -41,15 +41,15 @@ }, "dependencies": { "@metamask/eth-sig-util": "8.0.0", - "@nomicfoundation/hardhat-ethers": "3.0.8", + "@nomicfoundation/hardhat-ethers": "3.1.2", "@nomicfoundation/hardhat-network-helpers": "1.0.12", "@nomicfoundation/hardhat-verify": "2.0.14", - "@openzeppelin/contracts": "5.1.0", + "@openzeppelin/contracts": "5.5.0", "@uniswap/permit2-sdk": "1.3.0", "chai": "4.5.0", - "dotenv": "16.4.5", + "dotenv": "16.6.1", "ethereumjs-util": "7.1.5", - "ethers": "6.13.4", + "ethers": "6.15.0", "hardhat": "2.23.0", "hardhat-deploy": "0.14.0", "mocha-chai-jest-snapshot": "1.1.6", diff --git a/yarn.lock b/yarn.lock index 34848ca4..f3c5f830 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1397,10 +1397,10 @@ deep-eql "^4.0.1" ordinal "^1.0.3" -"@nomicfoundation/hardhat-ethers@3.0.8": - version "3.0.8" - resolved "https://registry.yarnpkg.com/@nomicfoundation/hardhat-ethers/-/hardhat-ethers-3.0.8.tgz#af078f566373abeb77e11cbe69fe3dd47f8bfc27" - integrity sha512-zhOZ4hdRORls31DTOqg+GmEZM0ujly8GGIuRY7t7szEk2zW/arY1qDug/py8AEktT00v5K+b6RvbVog+va51IA== +"@nomicfoundation/hardhat-ethers@3.1.2": + version "3.1.2" + resolved "https://registry.yarnpkg.com/@nomicfoundation/hardhat-ethers/-/hardhat-ethers-3.1.2.tgz#8f9e6ee32514e9a65b047735dca2c02c60e814ed" + integrity sha512-7xEaz2X8p47qWIAqtV2z03MmusheHm8bvY2mDlxo9JiT2BgSx59GSdv5+mzwOvsuKDbTij7oqDnwFyYOlHREEQ== dependencies: debug "^4.1.1" lodash.isequal "^4.5.0" @@ -1475,10 +1475,10 @@ "@nomicfoundation/solidity-analyzer-linux-x64-musl" "0.1.2" "@nomicfoundation/solidity-analyzer-win32-x64-msvc" "0.1.2" -"@openzeppelin/contracts@5.1.0": - version "5.1.0" - resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-5.1.0.tgz#4e61162f2a2bf414c4e10c45eca98ce5f1aadbd4" - integrity sha512-p1ULhl7BXzjjbha5aqst+QMLY+4/LCWADXOCsmLHRM77AqiPjnd9vvUN9sosUfhL9JGKpZ0TjEGxgvnizmWGSA== +"@openzeppelin/contracts@5.5.0": + version "5.5.0" + resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-5.5.0.tgz#24e8a2f9598de484dcb223512af656edf52bc0e8" + integrity sha512-R8hq4zmKKWP2c7OxeRgAcjZwvF5W0Qq2OIX7degrtdM52Q9xYr4MLJdUAVPKGUewNJ1qo+M6YiZLLnNUnjP/gg== "@pkgjs/parseargs@^0.11.0": version "0.11.0" @@ -3153,10 +3153,10 @@ doctrine@^3.0.0: dependencies: esutils "^2.0.2" -dotenv@16.4.5: - version "16.4.5" - resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f" - integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg== +dotenv@16.6.1: + version "16.6.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.6.1.tgz#773f0e69527a8315c7285d5ee73c4459d20a8020" + integrity sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow== dunder-proto@^1.0.0, dunder-proto@^1.0.1: version "1.0.1" @@ -3623,10 +3623,10 @@ ethereumjs-util@7.1.5, ethereumjs-util@^7.1.4: ethereum-cryptography "^0.1.3" rlp "^2.2.4" -ethers@6.13.4: - version "6.13.4" - resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.13.4.tgz#bd3e1c3dc1e7dc8ce10f9ffb4ee40967a651b53c" - integrity sha512-21YtnZVg4/zKkCQPjrDj38B1r4nQvTZLopUGMLQ1ePU2zV/joCfDC3t3iKQjWRzjjjbzR+mdAIoikeBRNkdllA== +ethers@6.15.0: + version "6.15.0" + resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.15.0.tgz#2980f2a3baf0509749b7e21f8692fa8a8349c0e3" + integrity sha512-Kf/3ZW54L4UT0pZtsY/rf+EkBU7Qi5nnhonjUb8yTXcxH3cdcWrV2cRyk0Xk/4jK6OoHhxxZHriyhje20If2hQ== dependencies: "@adraffy/ens-normalize" "1.10.1" "@noble/curves" "1.2.0"