cue modules: move stdlib to pkg/alpha.dagger.io
In preparation for Europa, we will vendor multiple CUE modules: - `pkg/alpha.dagger.io`: legacy non-europa packages - `pkg/dagger.io`: core Europa packages - `pkg/universe.dagger.io`: Europa universe Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
66
pkg/alpha.dagger.io/gcp/cloudrun/cloudrun.cue
Normal file
66
pkg/alpha.dagger.io/gcp/cloudrun/cloudrun.cue
Normal file
@@ -0,0 +1,66 @@
|
||||
package cloudrun
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"alpha.dagger.io/dagger/op"
|
||||
"alpha.dagger.io/gcp"
|
||||
)
|
||||
|
||||
// Service deploys a Cloud Run service based on provided GCR image
|
||||
#Service: {
|
||||
// GCP Config
|
||||
config: gcp.#Config
|
||||
|
||||
// Cloud Run service name
|
||||
name: string @dagger(input)
|
||||
|
||||
// GCR image ref
|
||||
image: string @dagger(input)
|
||||
|
||||
// Cloud Run platform
|
||||
platform: *"managed" | string @dagger(input)
|
||||
|
||||
// Cloud Run service exposed port
|
||||
port: *"80" | string @dagger(input)
|
||||
|
||||
// Cloud Run service environment variables
|
||||
env: [string]: string
|
||||
_envVars: [ for key, val in env {key + "=" + val}]
|
||||
|
||||
#up: [
|
||||
op.#Load & {
|
||||
from: gcp.#GCloud & {
|
||||
"config": config
|
||||
}
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"-c",
|
||||
#"""
|
||||
gcloud run deploy "$SERVICE_NAME" \
|
||||
--image "$IMAGE" \
|
||||
--region "$REGION" \
|
||||
--port "$PORT" \
|
||||
--platform "$PLATFORM" \
|
||||
--allow-unauthenticated \
|
||||
--set-env-vars "$ENV_VARS"
|
||||
"""#,
|
||||
]
|
||||
env: {
|
||||
SERVICE_NAME: name
|
||||
PLATFORM: platform
|
||||
REGION: config.region
|
||||
IMAGE: image
|
||||
PORT: port
|
||||
ENV_VARS: strings.Join(_envVars, ",")
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
18
pkg/alpha.dagger.io/gcp/cloudrun/tests/cloudrun.cue
Normal file
18
pkg/alpha.dagger.io/gcp/cloudrun/tests/cloudrun.cue
Normal file
@@ -0,0 +1,18 @@
|
||||
package cloudrun
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/gcp"
|
||||
"alpha.dagger.io/gcp/cloudrun"
|
||||
)
|
||||
|
||||
TestConfig: gcpConfig: gcp.#Config
|
||||
|
||||
TestCloudRun: deploy: cloudrun.#Service & {
|
||||
config: TestConfig.gcpConfig
|
||||
name: "todoapp"
|
||||
image: "gcr.io/dagger-ci/todoapp:latest"
|
||||
env: {
|
||||
FOO: "foo"
|
||||
BAR: "bar"
|
||||
}
|
||||
}
|
56
pkg/alpha.dagger.io/gcp/gcloud.cue
Normal file
56
pkg/alpha.dagger.io/gcp/gcloud.cue
Normal file
@@ -0,0 +1,56 @@
|
||||
package gcp
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger/op"
|
||||
"alpha.dagger.io/alpine"
|
||||
)
|
||||
|
||||
// Re-usable gcloud component
|
||||
#GCloud: {
|
||||
config: #Config
|
||||
version: string | *"366.0.0"
|
||||
package: [string]: string | bool
|
||||
|
||||
#up: [
|
||||
op.#Load & {
|
||||
from: alpine.#Image & {
|
||||
"package": package
|
||||
"package": bash: true
|
||||
"package": python3: true
|
||||
"package": jq: true
|
||||
"package": curl: true
|
||||
}
|
||||
},
|
||||
|
||||
// Install the gcloud cli
|
||||
op.#Exec & {
|
||||
args: ["sh", "-c",
|
||||
#"""
|
||||
curl -sfL https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-\#(version)-linux-x86_64.tar.gz | tar -C /usr/local -zx
|
||||
ln -s /usr/local/google-cloud-sdk/bin/gcloud /usr/local/bin
|
||||
ln -s /usr/local/google-cloud-sdk/bin/gsutil /usr/local/bin
|
||||
"""#,
|
||||
]
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
args: ["gcloud", "-q", "auth", "activate-service-account", "--key-file=/service_key"]
|
||||
mount: "/service_key": secret: config.serviceKey
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
args: ["gcloud", "-q", "config", "set", "project", config.project]
|
||||
},
|
||||
|
||||
if config.region != null {
|
||||
op.#Exec & {
|
||||
args: ["gcloud", "-q", "config", "set", "compute/region", config.region]
|
||||
}
|
||||
},
|
||||
if config.zone != null {
|
||||
op.#Exec & {
|
||||
args: ["gcloud", "-q", "config", "set", "compute/zone", config.zone]
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
18
pkg/alpha.dagger.io/gcp/gcp.cue
Normal file
18
pkg/alpha.dagger.io/gcp/gcp.cue
Normal file
@@ -0,0 +1,18 @@
|
||||
// Google Cloud Platform
|
||||
package gcp
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
)
|
||||
|
||||
// Base Google Cloud Config
|
||||
#Config: {
|
||||
// GCP region
|
||||
region: dagger.#Input & {*null | string}
|
||||
// GCP zone
|
||||
zone: dagger.#Input & {*null | string}
|
||||
// GCP project
|
||||
project: dagger.#Input & {string}
|
||||
// GCP service key
|
||||
serviceKey: dagger.#Input & {dagger.#Secret}
|
||||
}
|
47
pkg/alpha.dagger.io/gcp/gcr/gcr.cue
Normal file
47
pkg/alpha.dagger.io/gcp/gcr/gcr.cue
Normal file
@@ -0,0 +1,47 @@
|
||||
// Google Container Registry
|
||||
package gcr
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger/op"
|
||||
"alpha.dagger.io/gcp"
|
||||
)
|
||||
|
||||
// Credentials retriever for GCR
|
||||
#Credentials: {
|
||||
// GCP Config
|
||||
config: gcp.#Config
|
||||
|
||||
// GCR registry username
|
||||
username: "oauth2accesstoken" @dagger(output)
|
||||
|
||||
// GCR registry secret
|
||||
secret: {
|
||||
string
|
||||
|
||||
#up: [
|
||||
op.#Load & {
|
||||
from: gcp.#GCloud & {
|
||||
"config": config
|
||||
}
|
||||
},
|
||||
op.#Exec & {
|
||||
always: true
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"-c",
|
||||
#"""
|
||||
printf $(gcloud auth print-access-token) > /token.txt
|
||||
"""#,
|
||||
]
|
||||
},
|
||||
|
||||
op.#Export & {
|
||||
source: "/token.txt"
|
||||
},
|
||||
]
|
||||
} @dagger(output)
|
||||
}
|
86
pkg/alpha.dagger.io/gcp/gcr/tests/gcr.cue
Normal file
86
pkg/alpha.dagger.io/gcp/gcr/tests/gcr.cue
Normal file
@@ -0,0 +1,86 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/gcp"
|
||||
"alpha.dagger.io/gcp/gcr"
|
||||
"alpha.dagger.io/dagger/op"
|
||||
"alpha.dagger.io/random"
|
||||
)
|
||||
|
||||
TestConfig: gcpConfig: gcp.#Config
|
||||
|
||||
TestGCR: {
|
||||
suffix: random.#String & {
|
||||
seed: ""
|
||||
}
|
||||
|
||||
repository: "gcr.io/dagger-ci/test"
|
||||
tag: "test-gcr-\(suffix.out)"
|
||||
|
||||
creds: gcr.#Credentials & {
|
||||
config: TestConfig.gcpConfig
|
||||
}
|
||||
|
||||
push: {
|
||||
ref: "\(repository):\(tag)"
|
||||
|
||||
#up: [
|
||||
op.#DockerBuild & {
|
||||
dockerfile: """
|
||||
FROM alpine
|
||||
RUN echo \(suffix.out) > /test
|
||||
"""
|
||||
},
|
||||
|
||||
op.#DockerLogin & {
|
||||
target: repository
|
||||
username: creds.username
|
||||
secret: creds.secret
|
||||
},
|
||||
|
||||
op.#PushContainer & {
|
||||
"ref": ref
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
pull: #up: [
|
||||
op.#DockerLogin & {
|
||||
target: push.ref
|
||||
username: creds.username
|
||||
secret: creds.secret
|
||||
},
|
||||
|
||||
op.#FetchContainer & {
|
||||
ref: push.ref
|
||||
},
|
||||
]
|
||||
|
||||
verify: #up: [
|
||||
op.#Load & {
|
||||
from: pull
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
always: true
|
||||
args: [
|
||||
"sh", "-c", "test $(cat test) = \(suffix.out)",
|
||||
]
|
||||
},
|
||||
]
|
||||
|
||||
verifyBuild: #up: [
|
||||
op.#DockerLogin & {
|
||||
target: push.ref
|
||||
username: creds.username
|
||||
secret: creds.secret
|
||||
},
|
||||
|
||||
op.#DockerBuild & {
|
||||
dockerfile: #"""
|
||||
FROM \#(push.ref)
|
||||
RUN test $(cat test) = \#(suffix.out)
|
||||
"""#
|
||||
},
|
||||
]
|
||||
}
|
82
pkg/alpha.dagger.io/gcp/gcs/gcs.cue
Normal file
82
pkg/alpha.dagger.io/gcp/gcs/gcs.cue
Normal file
@@ -0,0 +1,82 @@
|
||||
// Google Cloud Storage
|
||||
package gcs
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/dagger/op"
|
||||
"alpha.dagger.io/gcp"
|
||||
)
|
||||
|
||||
// GCS Bucket object(s) sync
|
||||
#Object: {
|
||||
|
||||
// GCP Config
|
||||
config: gcp.#Config
|
||||
|
||||
// Source Artifact to upload to GCS
|
||||
source: dagger.#Artifact @dagger(input)
|
||||
|
||||
// Target GCS URL (eg. gs://<bucket-name>/<path>/<sub-path>)
|
||||
target: string @dagger(input)
|
||||
|
||||
// Delete files that already exist on remote destination
|
||||
delete: *false | true @dagger(input)
|
||||
|
||||
// Object content type
|
||||
contentType: string | *"" @dagger(input)
|
||||
|
||||
// Always write the object to GCS
|
||||
always: *true | false @dagger(input)
|
||||
|
||||
// URL of the uploaded GCS object
|
||||
url: {
|
||||
string
|
||||
|
||||
#up: [
|
||||
op.#Load & {
|
||||
from: gcp.#GCloud & {
|
||||
"config": config
|
||||
}
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
if always {
|
||||
always: true
|
||||
}
|
||||
env: {
|
||||
TARGET: target
|
||||
OPT_CONTENT_TYPE: contentType
|
||||
if delete {
|
||||
OPT_DELETE: "1"
|
||||
}
|
||||
}
|
||||
|
||||
mount: "/source": from: source
|
||||
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"-c",
|
||||
#"""
|
||||
opts=("-r")
|
||||
[ -n "$OPT_CONTENT_TYPE" ] && opts+="-h Content-Type:$OPT_CONTENT_TYPE"
|
||||
[ -n "$OPT_DELETE" ] && opts+="-d"
|
||||
gsutil rsync ${opts[@]} /source "$TARGET"
|
||||
echo -n "$TARGET" \
|
||||
| sed -E 's=^gs://([^/]*)/=https://storage.cloud.google.com/\1/=' \
|
||||
> /url
|
||||
"""#,
|
||||
|
||||
]
|
||||
},
|
||||
|
||||
op.#Export & {
|
||||
source: "/url"
|
||||
format: "string"
|
||||
},
|
||||
]
|
||||
} @dagger(output)
|
||||
}
|
43
pkg/alpha.dagger.io/gcp/gcs/tests/gcs.cue
Normal file
43
pkg/alpha.dagger.io/gcp/gcs/tests/gcs.cue
Normal file
@@ -0,0 +1,43 @@
|
||||
package gcs
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/gcp"
|
||||
"alpha.dagger.io/random"
|
||||
)
|
||||
|
||||
TestConfig: {
|
||||
gcpConfig: gcp.#Config
|
||||
bucket: string @dagger(input)
|
||||
}
|
||||
|
||||
TestDirectory: dagger.#Artifact
|
||||
|
||||
TestGCSObject: {
|
||||
suffix: random.#String & {
|
||||
seed: "gcs"
|
||||
}
|
||||
|
||||
target: "gs://\(TestConfig.bucket)/\(suffix.out)/"
|
||||
|
||||
deploy: #Object & {
|
||||
always: true
|
||||
config: TestConfig.gcpConfig
|
||||
source: TestDirectory
|
||||
"target": target
|
||||
}
|
||||
|
||||
verifyFile: #VerifyGCS & {
|
||||
config: TestConfig.gcpConfig
|
||||
target: deploy.target
|
||||
url: deploy.url
|
||||
file: "dirFile.txt"
|
||||
}
|
||||
|
||||
verifyDir: #VerifyGCS & {
|
||||
config: TestConfig.gcpConfig
|
||||
target: deploy.target
|
||||
url: deploy.url
|
||||
file: "foo.txt"
|
||||
}
|
||||
}
|
1
pkg/alpha.dagger.io/gcp/gcs/tests/testdata/bar/foo.txt
vendored
Normal file
1
pkg/alpha.dagger.io/gcp/gcs/tests/testdata/bar/foo.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Test recursivity
|
1
pkg/alpha.dagger.io/gcp/gcs/tests/testdata/dirFile.txt
vendored
Normal file
1
pkg/alpha.dagger.io/gcp/gcs/tests/testdata/dirFile.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Test directory
|
89
pkg/alpha.dagger.io/gcp/gcs/tests/verify.cue
Normal file
89
pkg/alpha.dagger.io/gcp/gcs/tests/verify.cue
Normal file
@@ -0,0 +1,89 @@
|
||||
package gcs
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/alpine"
|
||||
"alpha.dagger.io/dagger/op"
|
||||
"alpha.dagger.io/gcp"
|
||||
)
|
||||
|
||||
#List: {
|
||||
// GCP Config
|
||||
config: gcp.#Config
|
||||
|
||||
// Target GCP URL (e.g. gs://<bucket-name>/<path>/<sub-path>)
|
||||
target: string
|
||||
|
||||
// URL: dummy URL, used to force a dependency
|
||||
url: string
|
||||
|
||||
contents: {
|
||||
string
|
||||
|
||||
#up: [
|
||||
op.#Load & {
|
||||
from: gcp.#GCloud & {
|
||||
"config": config
|
||||
}
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"-c",
|
||||
#"""
|
||||
gsutil ls -r \#(target) > /contents
|
||||
"""#,
|
||||
]
|
||||
env: URL: url
|
||||
},
|
||||
|
||||
op.#Export & {
|
||||
source: "/contents"
|
||||
format: "string"
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
#VerifyGCS: {
|
||||
file: string
|
||||
config: gcp.#Config
|
||||
target: string
|
||||
url: string
|
||||
|
||||
lists: #List & {
|
||||
"config": config
|
||||
"target": target
|
||||
"url": url
|
||||
}
|
||||
|
||||
test: #up: [
|
||||
op.#Load & {
|
||||
from: alpine.#Image & {
|
||||
package: bash: true
|
||||
}
|
||||
},
|
||||
|
||||
op.#WriteFile & {
|
||||
dest: "/test"
|
||||
content: lists.contents
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
always: true
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"-c",
|
||||
"grep -q \(file) /test",
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
85
pkg/alpha.dagger.io/gcp/gke/gke.cue
Normal file
85
pkg/alpha.dagger.io/gcp/gke/gke.cue
Normal file
@@ -0,0 +1,85 @@
|
||||
// Google Kubernetes Engine
|
||||
package gke
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger/op"
|
||||
"alpha.dagger.io/gcp"
|
||||
)
|
||||
|
||||
// KubeConfig config outputs a valid kube-auth-config for kubectl client
|
||||
#KubeConfig: {
|
||||
// GCP Config
|
||||
config: gcp.#Config
|
||||
|
||||
// GKE cluster name
|
||||
clusterName: string @dagger(input)
|
||||
|
||||
// Kubectl version
|
||||
version: *"v1.19.9" | string @dagger(input)
|
||||
|
||||
// kubeconfig is the generated kube configuration file
|
||||
kubeconfig: {
|
||||
// FIXME There is a problem with dagger.#Secret type
|
||||
string
|
||||
|
||||
#up: [
|
||||
op.#Load & {
|
||||
from: gcp.#GCloud & {
|
||||
"config": config
|
||||
}
|
||||
},
|
||||
|
||||
op.#WriteFile & {
|
||||
dest: "/entrypoint.sh"
|
||||
content: #Code
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
always: true
|
||||
args: [
|
||||
"/bin/bash",
|
||||
"--noprofile",
|
||||
"--norc",
|
||||
"-eo",
|
||||
"pipefail",
|
||||
"/entrypoint.sh",
|
||||
]
|
||||
env: {
|
||||
GKE_CLUSTER: clusterName
|
||||
KUBECTL_VERSION: version
|
||||
}
|
||||
mount: "/cache/bin": "cache"
|
||||
},
|
||||
op.#Export & {
|
||||
source: "/kubeconfig"
|
||||
format: "string"
|
||||
},
|
||||
]
|
||||
} @dagger(output)
|
||||
}
|
||||
|
||||
#Code: #"""
|
||||
[ -e /cache/bin/kubectl ] || {
|
||||
curl -sfL https://dl.k8s.io/${KUBECTL_VERSION}/bin/linux/amd64/kubectl -o /cache/bin/kubectl \
|
||||
&& chmod +x /cache/bin/kubectl
|
||||
}
|
||||
|
||||
export KUBECONFIG=/kubeconfig
|
||||
export PATH="$PATH:/cache/bin"
|
||||
|
||||
# Generate a kube configiration
|
||||
gcloud -q container clusters get-credentials "$GKE_CLUSTER"
|
||||
|
||||
# Figure out the kubernetes username
|
||||
CONTEXT="$(kubectl config current-context)"
|
||||
USER="$(kubectl config view -o json | \
|
||||
jq -r ".contexts[] | select(.name==\"$CONTEXT\") | .context.user")"
|
||||
|
||||
# Grab a kubernetes access token
|
||||
ACCESS_TOKEN="$(gcloud -q config config-helper --format json --min-expiry 1h | \
|
||||
jq -r .credential.access_token)"
|
||||
|
||||
# Remove the user config and replace it with the token
|
||||
kubectl config unset "users.${USER}"
|
||||
kubectl config set-credentials "$USER" --token "$ACCESS_TOKEN"
|
||||
"""#
|
32
pkg/alpha.dagger.io/gcp/gke/tests/gke.cue
Normal file
32
pkg/alpha.dagger.io/gcp/gke/tests/gke.cue
Normal file
@@ -0,0 +1,32 @@
|
||||
package gke
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/gcp"
|
||||
"alpha.dagger.io/gcp/gke"
|
||||
"alpha.dagger.io/kubernetes"
|
||||
"alpha.dagger.io/dagger/op"
|
||||
)
|
||||
|
||||
TestConfig: gcpConfig: gcp.#Config
|
||||
|
||||
TestCluster: gke.#KubeConfig & {
|
||||
config: TestConfig.gcpConfig
|
||||
clusterName: "test-cluster"
|
||||
}
|
||||
|
||||
TestGKE: #up: [
|
||||
op.#Load & {
|
||||
from: kubernetes.#Kubectl
|
||||
},
|
||||
|
||||
op.#WriteFile & {
|
||||
dest: "/kubeconfig"
|
||||
content: TestCluster.kubeconfig
|
||||
},
|
||||
|
||||
op.#Exec & {
|
||||
always: true
|
||||
args: ["kubectl", "get", "nodes"]
|
||||
env: KUBECONFIG: "/kubeconfig"
|
||||
},
|
||||
]
|
76
pkg/alpha.dagger.io/gcp/secretmanager/secrets.cue
Normal file
76
pkg/alpha.dagger.io/gcp/secretmanager/secrets.cue
Normal file
@@ -0,0 +1,76 @@
|
||||
// Google Cloud Secret Manager
|
||||
package secretmanager
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/dagger/op"
|
||||
"alpha.dagger.io/gcp"
|
||||
"alpha.dagger.io/os"
|
||||
)
|
||||
|
||||
#Secrets: {
|
||||
// GCP Config
|
||||
config: gcp.#Config
|
||||
|
||||
// Map of secrets
|
||||
secrets: [name=string]: dagger.#Secret
|
||||
|
||||
// Deploy encrypted secrets
|
||||
deployment: os.#Container & {
|
||||
image: gcp.#GCloud & {"config": config}
|
||||
shell: path: "/bin/bash"
|
||||
always: true
|
||||
|
||||
for name, s in secrets {
|
||||
secret: "/tmp/secrets/\(name)": s
|
||||
}
|
||||
|
||||
command: #"""
|
||||
# Loop on all files, including hidden files
|
||||
shopt -s dotglob
|
||||
echo "{}" > /tmp/output.json
|
||||
for FILE in /tmp/secrets/*; do
|
||||
BOOL=0 # Boolean
|
||||
gcloud secrets describe "${FILE##*/}" 2>/dev/null > /dev/null
|
||||
status=$?
|
||||
|
||||
# If secret not found
|
||||
if [[ ! "${status}" -eq 0 ]]; then
|
||||
(\
|
||||
RES="$(gcloud secrets create "${FILE##*/}" --replication-policy automatic --data-file "${FILE}" --format='value(name)' 2>&1 | sed -n '1!p')" \
|
||||
&& cat <<< $(cat /tmp/output.json | jq ".|.\"${FILE##*/}\"=\"$RES\"") > /tmp/output.json \
|
||||
) || (echo "Error while creating secret ${FILE##*/}" >&2 && exit 1)
|
||||
BOOL=1
|
||||
else
|
||||
(\
|
||||
RES="$(gcloud secrets versions add "${FILE##*/}" --data-file "${FILE}" --format='value(name)' 2>&1 | sed -n '1!p')" \
|
||||
&& cat <<< $(cat /tmp/output.json | jq ".|.\"${FILE##*/}\"=\"$RES\"") > /tmp/output.json \
|
||||
) || (echo "Error while updating secret ${FILE##*/}" >&2 && exit 1)
|
||||
BOOL=1
|
||||
fi
|
||||
if [ $BOOL -eq 0 ]; then
|
||||
(\
|
||||
RES="$(gcloud secrets describe "${FILE##*/}" --format='value(name)' 2>&1)" \
|
||||
&& cat <<< $(cat /tmp/output.json | jq ".|.\"${FILE##*/}\"=\"$RES\"") > /tmp/output.json \
|
||||
) || (echo "Error while retrieving secret ${FILE##*/}" >&2 && exit 1)
|
||||
fi
|
||||
done
|
||||
"""#
|
||||
}
|
||||
|
||||
// dynamic references
|
||||
references: {
|
||||
[string]: string
|
||||
}
|
||||
|
||||
references: #up: [
|
||||
op.#Load & {
|
||||
from: deployment
|
||||
},
|
||||
|
||||
op.#Export & {
|
||||
source: "/tmp/output.json"
|
||||
format: "json"
|
||||
},
|
||||
]
|
||||
}
|
33
pkg/alpha.dagger.io/gcp/secretmanager/tests/secrets.cue
Normal file
33
pkg/alpha.dagger.io/gcp/secretmanager/tests/secrets.cue
Normal file
@@ -0,0 +1,33 @@
|
||||
package secretmanager
|
||||
|
||||
import (
|
||||
"alpha.dagger.io/dagger"
|
||||
"alpha.dagger.io/gcp"
|
||||
"alpha.dagger.io/gcp/secretmanager"
|
||||
"alpha.dagger.io/os"
|
||||
)
|
||||
|
||||
TestConfig: gcpConfig: gcp.#Config
|
||||
|
||||
TestSecrets: {
|
||||
secret: secretmanager.#Secrets & {
|
||||
config: TestConfig.gcpConfig
|
||||
secrets: {
|
||||
databasePassword: dagger.#Secret @dagger(input)
|
||||
}
|
||||
}
|
||||
|
||||
if len(secret.references) > 0 {
|
||||
cleanup: os.#Container & {
|
||||
image: gcp.#GCloud & {
|
||||
config: TestConfig.gcpConfig
|
||||
}
|
||||
shell: path: "/bin/bash"
|
||||
always: true
|
||||
|
||||
command: #"""
|
||||
gcloud -q secrets delete databasePassword
|
||||
"""#
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user