Skip to content

Commit

Permalink
feat: use ceramic version tag + minor naming updates
Browse files Browse the repository at this point in the history
  • Loading branch information
smrz2001 committed Jul 9, 2022
1 parent ed6a1c5 commit 73ea2cc
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 101 deletions.
46 changes: 23 additions & 23 deletions ci/cas.cue
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,32 @@ dagger.#Plan & {
dest: "/var/run/docker.sock"
}
always: true
script: contents: #"""
docker-compose down
docker-compose up -d
timeout=$TIMEOUT
until [[ $timeout -le 0 ]]; do
echo -e "\n=============== Startup Logs ===============\n"
docker-compose logs --timestamps --tail=100
curl --verbose --fail --connect-timeout 5 --location "$URL" > curl.out 2>&1 || true
script: contents: #"""
docker-compose down
docker-compose up -d
timeout=$TIMEOUT
until [[ $timeout -le 0 ]]; do
echo -e "\n=============== Startup Logs ===============\n"
docker-compose logs --timestamps --tail=100
curl --verbose --fail --connect-timeout 5 --location "$URL" > curl.out 2>&1 || true
if grep -q "200 OK" curl.out
then
echo Healthcheck passed
docker-compose down
exit 0
fi
if grep -q "200 OK" curl.out
then
echo Healthcheck passed
docker-compose down
exit 0
fi
sleep 1
timeout=$(( timeout - 1 ))
done
sleep 1
timeout=$(( timeout - 1 ))
done
if [ $timeout -le 0 ]; then
echo Healthcheck failed
docker-compose down
exit 1
fi
"""#
if [ $timeout -le 0 ]; then
echo Healthcheck failed
docker-compose down
exit 1
fi
"""#
}
}

Expand Down
8 changes: 4 additions & 4 deletions ci/cd-manager.cue
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ dagger.#Plan & {
AWS_ACCESS_KEY_ID: dagger.#Secret
AWS_SECRET_ACCESS_KEY: dagger.#Secret
// Runtime
DAGGER_LOG_FORMAT: string | *"plain"
DAGGER_LOG_LEVEL: string | *"info"
DAGGER_LOG_FORMAT: string | *"plain"
DAGGER_LOG_LEVEL: string | *"info"
}
client: commands: aws: {
name: "aws"
Expand Down Expand Up @@ -68,7 +68,7 @@ dagger.#Plan & {
AWS_ACCOUNT_ID: client.env.AWS_ACCOUNT_ID
AWS_ECR_SECRET: client.commands.aws.stdout
AWS_REGION: Region
REPO: "ceramic-qa-cd-manager"
REPO: "ceramic-qa-ops-cd-manager"
TAGS: _baseTags + ["qa"]
}
}
Expand All @@ -79,7 +79,7 @@ dagger.#Plan & {
AWS_ACCOUNT_ID: client.env.AWS_ACCOUNT_ID
AWS_ECR_SECRET: client.commands.aws.stdout
AWS_REGION: Region
REPO: "ceramic-\(EnvTag)-cd-manager"
REPO: "ceramic-\(EnvTag)-ops-cd-manager"
TAGS: _tags
}
}
Expand Down
90 changes: 69 additions & 21 deletions ci/ceramic.cue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"dagger.io/dagger"
"dagger.io/dagger/core"

"universe.dagger.io/alpine"
"universe.dagger.io/aws"
"universe.dagger.io/bash"
"universe.dagger.io/docker"

"github.com/3box/pipeline-tools/utils"
Expand All @@ -25,8 +27,8 @@ dagger.#Plan & {
DOCKERHUB_USERNAME: string
DOCKERHUB_TOKEN: dagger.#Secret
// Runtime
DAGGER_LOG_FORMAT: string | *"plain"
DAGGER_LOG_LEVEL: string | *"info"
DAGGER_LOG_FORMAT: string | *"plain"
DAGGER_LOG_LEVEL: string | *"info"
}
client: commands: aws: {
name: "aws"
Expand Down Expand Up @@ -70,7 +72,7 @@ dagger.#Plan & {
_imageSource: client.filesystem.imageSource.read.contents
_dockerfile: client.filesystem.dockerfile.read.contents

testJs: utils.#TestNode & {
testJs: utils.#TestNode & {
src: _fullSource
run: env: IPFS_FLAVOR: "js"
}
Expand All @@ -96,25 +98,64 @@ dagger.#Plan & {
dockerHost: client.network."unix:///var/run/docker.sock".connect
}

push: [Region=aws.#Region]: [EnvTag=#EnvTag]: [Branch=#Branch]: [Sha=#Sha]: [ShaTag=#ShaTag]: {
_baseTags: ["\(EnvTag)", "\(Branch)", "\(Sha)", "\(ShaTag)"]
_tags: [...string]
version: {
_cli: alpine.#Build & {
packages: {
bash: {}
git: {}
npm: {}
}
}
run: bash.#Run & {
input: _cli.output
workdir: "./src"
mounts: source: {
dest: "/src"
contents: _fullSource
}
script: contents: #"""
npm install -g genversion
cd packages/cli
genversion version.ts
echo -n $(git rev-parse --abbrev-ref HEAD) > /branch
echo -n $(git rev-parse HEAD) > /sha
echo -n $(git rev-parse --short=12 HEAD) > /shaTag
echo -n $(cat version.ts | sed -n "s/^.*'\(.*\)'.*$/\1/ p") > /version
"""#
export: files: {
"/branch": string
"/sha": string
"/shaTag": string
"/version": string
}
}
branch: run.export.files["/branch"]
sha: run.export.files["/sha"]
shaTag: run.export.files["/shaTag"]
version: run.export.files["/version"]
}

push: [Region=aws.#Region]: [EnvTag=#EnvTag]: [Branch=#Branch]: [Sha=#Sha]: [ShaTag=#ShaTag]: [Version=string]: {
_tags: ["\(EnvTag)", "\(Branch)", "\(Sha)", "\(ShaTag)", "\(Version)"]
_extraTags: [...string] | *[]
if EnvTag == "prod"
{
_extraTags: ["latest"]
}
if EnvTag == "dev"
{
Branch == "main"
_tags: _baseTags + ["latest"]
} | {
_tags: _baseTags
_extraTags: ["qa"]
}
ecr: {
if Branch == "develop" {
if EnvTag == "dev" {
qa: utils.#ECR & {
img: _image.output
env: {
AWS_ACCOUNT_ID: client.env.AWS_ACCOUNT_ID
AWS_ECR_SECRET: client.commands.aws.stdout
AWS_REGION: Region
REPO: "ceramic-qa"
TAGS: _baseTags + ["qa"]
TAGS: _tags + _extraTags
}
}
}
Expand All @@ -125,7 +166,7 @@ dagger.#Plan & {
AWS_ECR_SECRET: client.commands.aws.stdout
AWS_REGION: Region
REPO: "ceramic-\(EnvTag)"
TAGS: _tags
TAGS: _tags + _extraTags
}
}
}
Expand All @@ -135,25 +176,32 @@ dagger.#Plan & {
DOCKERHUB_USERNAME: client.env.DOCKERHUB_USERNAME
DOCKERHUB_TOKEN: client.env.DOCKERHUB_TOKEN
REPO: _repo
TAGS: _tags
TAGS: _tags + _extraTags
}
}
}

queue: [Region=aws.#Region]: [EnvTag=string]: [Branch=string]: [Sha=string]: [ShaTag=string]: utils.#Queue & {
queue: [Region=aws.#Region]: [EnvTag=string]: utils.#Queue & {
_version: version
_envTag: string | *EnvTag
// Push to the QA queue for "dev"
if EnvTag == "dev"
{
_envTag: "qa"
}
env: {
AWS_ACCOUNT_ID: client.env.AWS_ACCOUNT_ID
AWS_ACCESS_KEY_ID: client.env.AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: client.env.AWS_SECRET_ACCESS_KEY
AWS_REGION: Region
ENV_TAG: _envTag
}
params: {
event: "deploy"
repo: _repo
envTag: EnvTag
branch: Branch
sha: Sha
shaTag: ShaTag
event: "deploy"
component: "ceramic"
sha: "\(_version.sha)"
shaTag: "\(_version.shaTag)"
version: "\(_version.version)"
}
}

Expand Down
34 changes: 17 additions & 17 deletions utils/docs.cue
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import (
)

#Docs: {
src: dagger.#FS
ver: int | *16
src: dagger.#FS
ver: int | *16

_node: docker.#Pull & {
source: "node:\(ver)"
_node: docker.#Pull & {
source: "node:\(ver)"
}
run: bash.#Run & {
input: _node.output
workdir: "./src"
mounts: source: {
dest: "/src"
contents: src
}
script: contents: #"""
npm ci
npm run build
npm run docs
"""#
}
run: bash.#Run & {
input: _node.output
workdir: "./src"
mounts: source: {
dest: "/src"
contents: src
}
script: contents: #"""
npm ci
npm run build
npm run docs
"""#
}
}
14 changes: 7 additions & 7 deletions utils/queue.cue
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import (
AWS_ACCESS_KEY_ID: dagger.#Secret
AWS_SECRET_ACCESS_KEY: dagger.#Secret
AWS_REGION: aws.#Region
ENV_TAG: string
}

params: {
event: "deploy" | "smoke" | "e2e" | "anchor"
envTag: "dev" | "qa" | "tnet" | "prod"
repo: "js-ceramic" | "ceramic-anchor-service" | "go-ipfs-daemon"
branch: "dev" | "develop" | "release-candidate" | "tnet" | "main" | "master"
sha: string
shaTag: string
event: "deploy"
component: "ceramic" | "cas" | "ipfs"
sha: string
shaTag: string
version: string | *""
}

send: cli.#Command & {
Expand All @@ -37,7 +37,7 @@ import (
command: "send-message"
args: [
"--queue-url",
"https://sqs.\(env.AWS_REGION).amazonaws.com/\(env.AWS_ACCOUNT_ID)/ceramic-ci-\(params.envTag).fifo",
"https://sqs.\(env.AWS_REGION).amazonaws.com/\(env.AWS_ACCOUNT_ID)/ceramic-\(env.ENV_TAG)-ops.fifo",
"--message-body",
"\"\(json.Marshal(params))\"",
"--message-group-id",
Expand Down
4 changes: 2 additions & 2 deletions utils/runner.cue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package utils

import (
"universe.dagger.io/alpine"
"universe.dagger.io/docker"
"universe.dagger.io/alpine"
"universe.dagger.io/docker"
)

#Runner: {
Expand Down
54 changes: 27 additions & 27 deletions utils/test.cue
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ import (
)

#TestNode: {
src: dagger.#FS
ver: int | *16
src: dagger.#FS
ver: int | *16

_node: docker.#Pull & {
source: "node:\(ver)"
}
run: bash.#Run & {
env: NODE_OPTIONS: "--max_old_space_size=4096"
input: _node.output
workdir: "./src"
mounts: source: {
dest: "/src"
contents: src
}
script: contents: #"""
npm ci
npm run lint
npm run build
npm run test
"""#
}
_node: docker.#Pull & {
source: "node:\(ver)"
}
run: bash.#Run & {
env: NODE_OPTIONS: "--max_old_space_size=4096"
input: _node.output
workdir: "./src"
mounts: source: {
dest: "/src"
contents: src
}
script: contents: #"""
npm ci
npm run lint
npm run build
npm run test
"""#
}
}

#TestImage: {
Expand Down Expand Up @@ -58,7 +58,7 @@ import (
command: {
name: "sh"
flags: "-c": #"""
docker run -d --rm --name "$IMAGE_NAME" -p "$PORTS" "$IMAGE_NAME"
docker run -d --name "$IMAGE_NAME" -p "$PORTS" "$IMAGE_NAME"
"""#
}
}
Expand Down Expand Up @@ -130,10 +130,10 @@ import (
bash: {}
}
}
run: bash.#Run & {
input: _cli.output
script: contents: #"""
echo "I'm a successful test!"
"""#
}
run: bash.#Run & {
input: _cli.output
script: contents: #"""
echo "I'm a successful test!"
"""#
}
}

0 comments on commit 73ea2cc

Please sign in to comment.