Skip to content

Commit

Permalink
CRIB Devspace Cleanup (#12308)
Browse files Browse the repository at this point in the history
* Create simplified goreleaser file for devspace

* Reorder versioning to avoid db semver failures

* Cleanup devspace file via using devspace native functionality

* Remove redundant commit from version

* Use .env

* Remove redundant pipeline

* Remove dead docs

* Update docs to reflect new devspace changes

* Add support for tag overrides

* Update docs for image overrides

* Cleanup flag syntax

---------

Co-authored-by: Sergey Kudasov <[email protected]>
  • Loading branch information
HenryNguyen5 and skudasov authored Mar 8, 2024
1 parent 37e1bdc commit 1cdc71d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 127 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ tools/clroot/db.sqlite3-wal
.DS_Store
.envrc
.env*
!charts/chainlink-cluster/.env.example
!.github/actions/setup-postgres/.env
.direnv
.idea
Expand Down
27 changes: 9 additions & 18 deletions .goreleaser.devspace.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
## goreleaser <1.14.0
project_name: chainlink
project_name: chainlink-devspace

env:
- ZIG_EXEC={{ if index .Env "ZIG_EXEC" }}{{ .Env.ZIG_EXEC }}{{ else }}zig{{ end }}
- IMAGE_PREFIX={{ if index .Env "IMAGE_PREFIX" }}{{ .Env.IMAGE_PREFIX }}{{ else }}localhost:5001{{ end }}
- IMAGE_LABEL_DESCRIPTION="node of the decentralized oracle network, bridging on and off-chain computation"
- IMAGE_LABEL_LICENSES="MIT"
- IMAGE_LABEL_SOURCE="https://github.com/smartcontractkit/{{ .ProjectName }}"
Expand All @@ -13,7 +12,6 @@ before:
- go mod tidy
- ./tools/bin/goreleaser_utils before_hook


# See https://goreleaser.com/customization/build/
builds:
- binary: chainlink
Expand All @@ -33,8 +31,9 @@ builds:
- -buildmode=pie
ldflags:
- -s -w -r=$ORIGIN/libs
- -X github.com/smartcontractkit/chainlink/v2/core/static.Version={{ .Env.CHAINLINK_VERSION }}
- -X github.com/smartcontractkit/chainlink/v2/core/static.Version={{ .Version }}
- -X github.com/smartcontractkit/chainlink/v2/core/static.Sha={{ .FullCommit }}

# See https://goreleaser.com/customization/docker/
dockers:
- id: linux-amd64
Expand All @@ -56,30 +55,22 @@ dockers:
- "--label=org.opencontainers.image.revision={{ .FullCommit }}"
- "--label=org.opencontainers.image.source={{ .Env.IMAGE_LABEL_SOURCE }}"
- "--label=org.opencontainers.image.title={{ .ProjectName }}"
- "--label=org.opencontainers.image.version={{ .Env.CHAINLINK_VERSION }}"
- "--label=org.opencontainers.image.version={{ .Version }}"
- "--label=org.opencontainers.image.url={{ .Env.IMAGE_LABEL_SOURCE }}"
image_templates:
- "{{ .Env.IMAGE_PREFIX }}/{{ .ProjectName }}-develop:develop-amd64"
- "{{ .Env.IMAGE_PREFIX }}/{{ .ProjectName }}-develop:sha-{{ .ShortCommit }}-amd64"
- "{{ .Env.IMAGE }}"

# See https://goreleaser.com/customization/docker_manifest/
docker_manifests:
- name_template: "{{ .Env.IMAGE_PREFIX }}/{{ .ProjectName }}-develop:develop"
- name_template: "{{ .Env.IMAGE }}"
image_templates:
- "{{ .Env.IMAGE_PREFIX }}/{{ .ProjectName }}-develop:develop-amd64"
- name_template: "{{ .Env.IMAGE_PREFIX }}/{{ .ProjectName }}-develop:sha-{{ .ShortCommit }}"
image_templates:
- "{{ .Env.IMAGE_PREFIX }}/{{ .ProjectName }}-develop:sha-{{ .ShortCommit }}-amd64"

# See https://goreleaser.com/customization/docker_sign/
docker_signs:
- artifacts: all
stdin: "{{ .Env.COSIGN_PASSWORD }}"
- "{{ .Env.IMAGE }}"

checksum:
name_template: "checksums.txt"

snapshot:
name_template: "{{ .Env.CHAINLINK_VERSION }}-{{ .ShortCommit }}"
name_template: '{{ .Env.CHAINLINK_VERSION }}-{{ .Runtime.Goarch }}-{{ .Now.Format "2006-01-02-15-04-05Z" }}'

changelog:
sort: asc
Expand Down
17 changes: 17 additions & 0 deletions charts/chainlink-cluster/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The image that will be used for the Chainlink nodes.
DEVSPACE_IMAGE=

# This is a comma separated list of CIDR blocks that will be allowed to access the ingress.
DEVSPACE_INGRESS_CIDRS=

# This is the base domain in AWS Route 53 that our ingress subdomains will use.
DEVSPACE_INGRESS_BASE_DOMAIN=

# This is the ARN of the AWS ACM certificate that will be used for the ingress.
DEVSPACE_INGRESS_CERT_ARN=

# Time to wait for pods to be in `Ready` condition
DEVSPACE_K8S_POD_WAIT_TIMEOUT=600s

# The duration that the namespace and all of its associated resources will be kept alive.
NS_TTL=72h
40 changes: 11 additions & 29 deletions charts/chainlink-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ export DEVSPACE_IMAGE="..."
./setup.sh ${my-personal-namespace-name-crib}
```

Build and deploy current commit
Create a .env file based on the .env.sample file
```sh
cp .env.sample .env
# Fill in the required values in .env
```

Build and deploy the current state of your repository
```
devspace deploy
```
Expand All @@ -37,28 +43,17 @@ Valid values are `1h`, `2m`, `3s`, etc. Go time format is invalid `1h2m3s`
devspace run ttl ${namespace} 120h
```

If you don't need to build use
```
devspace deploy --skip-build
```

To deploy particular commit (must be in the registry) use
If you want to deploy an image tag that is already available in ECR, use:
```
devspace deploy --skip-build ${short_sha_of_image}
# -o is override-image-tag
devspace deploy -o "<image-tag>"
```

Forward ports to check UI or run tests
```
devspace run connect ${my-personal-namespace-name-crib}
```

Update some Go code of Chainlink node and quickly sync your cluster
```
devspace dev
```

To reset pods to original image just checkout needed commit and do `devspace deploy` again

Destroy the cluster
```
devspace purge
Expand All @@ -69,19 +64,6 @@ Check this [doc](../../integration-tests/load/ocr/README.md)

If you used `devspace dev ...` always use `devspace reset pods` to switch the pods back

## Debug existing cluster
If you need to debug CL node that is already deployed change `dev.app.container` and `dev.app.labelSelector` in [devspace.yaml](devspace.yaml) if they are not default and run:
```
devspace dev -p node
```

## Automatic file sync
When you run `devspace dev` your files described in `dev.app.sync` of [devspace.yaml](devspace.yaml) will be uploaded to the switched container

After that all the changes will be synced automatically

Check `.profiles` to understand what is uploaded in profiles `runner` and `node`

# Helm
If you would like to use `helm` directly, please uncomment data in `values.yaml`
## Install from local files
Expand Down Expand Up @@ -144,4 +126,4 @@ export DASHBOARD_NAME=ChainlinkClusterDebug
go run dashboard/cmd/dashboard_deploy.go
```
Open Grafana folder `DashboardCoreDebug` and find dashboard `ChainlinkClusterDebug`
Open Grafana folder `DashboardCoreDebug` and find dashboard `ChainlinkClusterDebug`
115 changes: 35 additions & 80 deletions charts/chainlink-cluster/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,40 @@ version: v2beta1
name: chainlink

vars:
NS_TTL: 72h
DEVSPACE_IMAGE:
noCache: true
source: env
# This is the base domain in AWS Route 53 that our ingress subdomains will use.
DEVSPACE_INGRESS_BASE_DOMAIN:
source: env
# This is the ARN of the AWS ACM certificate that will be used for the ingress.
DEVSPACE_INGRESS_CERT_ARN:
source: env
# This is a comma separated list of CIDR blocks that will be allowed to access the ingress.
DEVSPACE_INGRESS_CIDRS:
source: env
# Time to wait for pods to be in `Ready` condition
DEVSPACE_K8S_POD_WAIT_TIMEOUT: 600s
DEVSPACE_ENV_FILE: .env

# This is a list of `pipelines` that DevSpace can execute (you can define your own)
pipelines:
dev:
# We don't need a rollout here and image haven't been really changed,
# may not deserve to be commited, so we are just rebooting the app pods
run: |-
devspace run-pipeline deploy
kubectl get pods -n ${DEVSPACE_NAMESPACE} --no-headers=true | grep '^app-node-' | awk '{print $1}' | xargs kubectl delete pod -n ${DEVSPACE_NAMESPACE}
kubectl wait pods -n ${DEVSPACE_NAMESPACE} --selector=app=app --for=condition=Ready --timeout=${DEVSPACE_K8S_POD_WAIT_TIMEOUT}
# You can run this pipeline via `devspace deploy` (or `devspace run-pipeline deploy`)
deploy:
run: |-
set -o pipefail
echo "Removing .devspace cache!"
rm -rf .devspace/ || true
registry_id=$(echo "$DEVSPACE_IMAGE" | cut -d'.' -f1)
# Login into registry
echo "Authorizing into ECR registry"
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin ${registry_id}.dkr.ecr.us-west-2.amazonaws.com
flags:
- name: override-image-tag
short: o
type: string
description: "If specified, the specified tag will be used instead of building a new image"

run: |-
tagOverride=$(get_flag "override-image-tag")
run_dependencies --all
ensure_pull_secrets --all
build_images --all
kubectl label namespace ${DEVSPACE_NAMESPACE} cleanup.kyverno.io/ttl=${NS_TTL} || true
kubectl label namespace/${DEVSPACE_NAMESPACE} network=crib || true
tag=$(git rev-parse --short HEAD)
image=${DEVSPACE_IMAGE}:$tag
echo "Checking tag: '$tag'"
repository_name="chainlink-devspace"
desired_tag=$tag
if [ -n "$tagOverride" ]; then
image=${DEVSPACE_IMAGE}:${tagOverride}
echo "Using user provided image: $image"
# Check if the desired tag is present in the repository
image_list=$(aws ecr list-images --repository-name "$repository_name")
tag_exists=$(echo "$image_list" | jq -e '.imageIds[] | select(.imageTag == "'"${desired_tag}"'")' >/dev/null && echo true || echo false)
args=""
for i in {0..5}; do
args+="--set=helm.values.chainlink.nodes[$i].image=$image "
done
# Check the value of the tag_exists variable
if [ "$tag_exists" = "true" ]; then
echo "Image tag '$tag' found."
create_deployments app $args
else
echo "Image tag '$tag' not found. Please build the image using 'devspace deploy'"
exit 1
build_images --all
create_deployments app
fi
create_deployments app \
--set=helm.values.chainlink.nodes[0].image=$image \
--set=helm.values.chainlink.nodes[1].image=$image \
--set=helm.values.chainlink.nodes[2].image=$image \
--set=helm.values.chainlink.nodes[3].image=$image \
--set=helm.values.chainlink.nodes[4].image=$image \
--set=helm.values.chainlink.nodes[5].image=$image
echo
echo "Namespace ${DEVSPACE_NAMESPACE} will be deleted in ${NS_TTL}"
echo "To extend the TTL for e.g. 72 hours, run: devspace run ttl ${DEVSPACE_NAMESPACE} 72h"
kubectl label namespace ${DEVSPACE_NAMESPACE} cleanup.kyverno.io/ttl=${NS_TTL} || true
kubectl label namespace/${DEVSPACE_NAMESPACE} network=crib || true
echo
echo "############################################"
Expand All @@ -98,24 +60,16 @@ images:
app:
image: ${DEVSPACE_IMAGE}
tags:
- $(git rev-parse --short HEAD)
- ${devspace.namespace}-${devspace.timestamp}
custom:
skipImageArg: true
command: |-
TOPLEVEL=$(git rev-parse --show-toplevel)
pushd $TOPLEVEL
pwd
goreleaser --version
MACOS_SDK_DIR=$(pwd)/tools/bin/MacOSX12.3.sdk ./tools/bin/goreleaser_wrapper release --snapshot --clean --config .goreleaser.devspace.yaml
popd
BUILT_IMAGE=$(cat $TOPLEVEL/dist/artifacts.json | jq -r '.[] | select(.type == "Docker Image" and .goarch == "amd64" and (.name | contains("sha")) and ( .name | contains("root") | not) ) | .name')
GIT_ROOT=$(git rev-parse --show-toplevel)
cd $GIT_ROOT
echo "Tagging and pushing image"
tag=$(git rev-parse --short HEAD)
TAGGED_IMAGE=${DEVSPACE_IMAGE}:$tag
docker tag $BUILT_IMAGE ${runtime.images.app.image}:${runtime.images.app.tag}
echo "Tagged image: $TAGGED_IMAGE"
docker push $TAGGED_IMAGE
image=${runtime.images.app}
MACOS_SDK_DIR=$(pwd)/tools/bin/MacOSX12.3.sdk IMAGE=$image ./tools/bin/goreleaser_wrapper release --snapshot --clean --config .goreleaser.devspace.yaml
docker push $image
hooks:
- wait:
running: true
Expand All @@ -131,6 +85,7 @@ hooks:
# This is a list of `deployments` that DevSpace can create for this project
deployments:
app:
updateImageTags: false
namespace: ${DEVSPACE_NAMESPACE}
helm:
releaseName: "app"
Expand All @@ -157,7 +112,7 @@ deployments:
p2p_port: 6690
nodes:
- name: node-1
image: ${DEVSPACE_IMAGE}
image: ${runtime.images.app}
# default resources are 300m/1Gi
# first node need more resources to build faster inside container
# at least 2Gi of memory is required otherwise build will fail (OOM)
Expand Down Expand Up @@ -201,15 +156,15 @@ deployments:
# or use overridesToml to override some part of configuration
# overridesToml: |
- name: node-2
image: ${DEVSPACE_IMAGE}
image: ${runtime.images.app}
- name: node-3
image: ${DEVSPACE_IMAGE}
image: ${runtime.images.app}
- name: node-4
image: ${DEVSPACE_IMAGE}
image: ${runtime.images.app}
- name: node-5
image: ${DEVSPACE_IMAGE}
image: ${runtime.images.app}
- name: node-6
image: ${DEVSPACE_IMAGE}
image: ${runtime.images.app}

# each CL node have a dedicated PostgreSQL 11.15
# use StatefulSet by setting:
Expand Down Expand Up @@ -404,4 +359,4 @@ deployments:
podAnnotations:
nodeSelector:
tolerations:
affinity:
affinity:

0 comments on commit 1cdc71d

Please sign in to comment.