Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,47 @@ jobs:
build-deploy:
runs-on: self-hosted
env:
SCROLL_REGISTRY_PR_NAMESPACE: druid-team-experimental
SCROLL_REGISTRY_ENDPOINT: ${{ secrets.SCROLL_REGISTRY_ENDPOINT }}
SCROLL_REGISTRY_API_KEY: ${{ secrets.SCROLL_REGISTRY_API_KEY }}
SCROLL_REGISTRY_API_SECRET: ${{ secrets.SCROLL_REGISTRY_API_SECRET }}
SCROLL_REGISTRY_BUCKET: ${{ secrets.SCROLL_REGISTRY_BUCKET_STAGING }}
DRUID_CLI_VERSION: pr-76
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ">=1.19.3"
- run: apt update && apt install -y make
- run: make build-tree
- name: Build scroll tree
env:
SCROLL_REGISTRY_HOST: ${{ secrets.SCROLL_REGISTRY_HOST }}
run: |
if [ "${{ github.event.pull_request.head.repo.full_name }}" = "${{ github.repository }}" ]; then
registry_host="${SCROLL_REGISTRY_HOST#http://}"
registry_host="${registry_host#https://}"
registry_host="${registry_host%%/*}"
export DRUID_COLDSTARTER_IMAGE="${registry_host}/${SCROLL_REGISTRY_PR_NAMESPACE}/druid:stable-pr${{ github.event.pull_request.number }}"
fi
make build-tree
- name: Get registry binary
uses: robinraju/release-downloader@v1.7
with:
repository: "highcard-dev/druid-cli"
latest: true
fileName: "druid"
token: ${{ secrets.GO_REPO_TOKEN }}
- run: chmod +x ./druid
if: github.event.pull_request.head.repo.full_name == github.repository
env:
GH_TOKEN: ${{ secrets.GO_REPO_TOKEN }}
run: |
gh release download "$DRUID_CLI_VERSION" --repo highcard-dev/druid-cli --pattern druid --clobber
- name: Install druid
run: mv ./druid /usr/local/bin/druid
- run: ./scripts/validate_all_scrolls.sh
if: github.event.pull_request.head.repo.full_name == github.repository
run: |
chmod +x druid
mv druid /usr/local/bin/druid
- name: Validate all scrolls
run: ./scripts/validate_all_scrolls.sh
- name: Login to registry
if: github.event.pull_request.head.repo.full_name == github.repository
run: druid login --host ${{ secrets.SCROLL_REGISTRY_HOST }} --user '${{ secrets.SCROLL_REGISTRY_USER }}' --password ${{ secrets.SCROLL_REGISTRY_PASSWORD }}
- name: Push experimental PR tags
if: github.event.pull_request.head.repo.full_name == github.repository
env:
SCROLL_REGISTRY_HOST: ${{ secrets.SCROLL_REGISTRY_HOST }}
run: ./scripts/push.sh "${{ github.event.pull_request.number }}"
230 changes: 115 additions & 115 deletions .github/workflows/release.yml

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions generate-scrolls.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"
"strings"
"text/template"
"unicode"

cp "github.com/otiai10/copy"

Expand All @@ -19,6 +20,7 @@ type TemplateVars struct {
Artifact string
Version string
VersionEscaped string
ColdstarterImage string
Artifacts map[string]string
ArtifactsUnescaped map[string]string
Vars map[string]string
Expand Down Expand Up @@ -69,12 +71,31 @@ func main() {
"split": func(sep, s string) []string {
return strings.Split(s, sep)
},
"upper": strings.ToUpper,
"env": func(value string) string {
var out strings.Builder
for i, r := range value {
if i > 0 && unicode.IsUpper(r) {
out.WriteByte('_')
}
if r == '-' || r == ' ' {
out.WriteByte('_')
continue
}
out.WriteRune(unicode.ToUpper(r))
}
return out.String()
},
}
scollYamltemplate, err := template.New(filepath.Base(scrollYamlTemplate)).Funcs(funcMap).ParseFiles(scrollYamlTemplate)
// Capture any error
if err != nil {
log.Fatalln(err)
}
coldstarterImage := os.Getenv("DRUID_COLDSTARTER_IMAGE")
if coldstarterImage == "" {
coldstarterImage = "artifacts.druid.gg/druid-team/druid:stable"
}

//iterate through artifacts and generate scroll.yaml files
for version, artifact := range artifacts {
Expand All @@ -83,6 +104,7 @@ func main() {
templateVars.Artifact = artifact
templateVars.Version = version
templateVars.VersionEscaped = strings.Replace(version, ".", "-", -1)
templateVars.ColdstarterImage = coldstarterImage
templateVars.Artifacts = GetArtifactsAbove(version, artifacts, true)
templateVars.ArtifactsUnescaped = GetArtifactsAbove(version, artifacts, false)
if varsBytes != nil && vars[version] == nil {
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ require (
github.com/otiai10/copy v1.12.0
)

require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
require (
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ github.com/otiai10/copy v1.12.0/go.mod h1:rSaLseMUsZFFbsFGc7wCJnnkTAvdc5L6VWxPE4
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
98 changes: 98 additions & 0 deletions scripts/push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash

set -euo pipefail

pr_number="${1:?usage: $0 <pr-number>}"
registry_host="${SCROLL_REGISTRY_HOST:?SCROLL_REGISTRY_HOST is required}"
registry_host="${registry_host#http://}"
registry_host="${registry_host#https://}"
registry_host="${registry_host%%/*}"

namespace="${SCROLL_REGISTRY_PR_NAMESPACE:-druid-team-experimental}"
runtime_namespace="${SCROLL_REGISTRY_RUNTIME_NAMESPACE:-druid-team}"
runtime_image="${DRUID_SCROLL_RUNTIME_IMAGE:-${registry_host}/${runtime_namespace}/druid:stable-nix}"
roots="${SCROLL_PR_ROOTS:-}"

yaml_value() {
awk -F':[[:space:]]*' -v key="$2" '
$1 == key {
value = $2
gsub(/^"/, "", value)
gsub(/"$/, "", value)
print value
exit
}
' "$1"
}

scroll_dirs() {
if [[ -n "$roots" ]]; then
for root in $roots; do
for dir in "$root"/*; do
[[ -f "$dir/scroll.yaml" ]] || continue
printf '%s\n' "$dir"
done
[[ -f "$root/scroll.yaml" ]] && printf '%s\n' "$root"
done
return
fi
find ./scrolls -type f -name scroll.yaml -print | sed 's#/scroll.yaml$##' | sort
}

port_args() {
awk '
/^ports:/ { in_ports=1; next }
/^[^[:space:]-]/ { in_ports=0 }
in_ports && /^[[:space:]]*-[[:space:]]*name:/ {
name=$0
sub(/^[[:space:]]*-[[:space:]]*name:[[:space:]]*/, "", name)
gsub(/"/, "", name)
}
in_ports && /^[[:space:]]*port:/ {
port=$0
sub(/^[[:space:]]*port:[[:space:]]*/, "", port)
if (name != "" && port != "") {
printf " -p %s=%s", name, port
}
}
' "$1/scroll.yaml"
}

category_for_dir() {
local dir="$1"
dir="${dir#./scrolls/}"
echo "${dir%%/*}"
}

push_dir() {
local dir="$1"
local name app_version image artifact ports category

if [[ "$dir" == ./scrolls/.sample || "$dir" == ./scrolls/.sample/* ]]; then
echo "Skipping ${dir}: sample scrolls are validation fixtures"
return
fi

name="$(yaml_value "$dir/scroll.yaml" name)"
app_version="$(yaml_value "$dir/scroll.yaml" app_version)"
if [[ "$app_version" == "latest" ]]; then
echo "Skipping ${dir}: PR previews do not publish latest tags"
return
fi

image="${name##*/}"
artifact="${registry_host}/${namespace}/${image}:${app_version}-pr${pr_number}"
ports="$(port_args "$dir")"
category="$(category_for_dir "$dir")"

echo "Pushing ${artifact} from ${dir}"
# shellcheck disable=SC2086
druid push "$artifact" "$dir" $ports \
-i "$runtime_image" \
--min-disk 3Gi --min-ram 512Mi --min-cpu 0.25 \
--smart --category "$category"
}

while IFS= read -r dir; do
push_dir "$dir"
done < <(scroll_dirs)
Loading
Loading