Skip to content

Commit

Permalink
fix: ytt params
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipe Forattini committed Apr 29, 2022
1 parent a2a82c7 commit 2cac572
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 60 deletions.
28 changes: 10 additions & 18 deletions .github/workflows/service-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
type: string
required: false
default: master
ecosystem:
type: string
required: false
containerRegistry:
type: string
required: false
Expand Down Expand Up @@ -352,19 +355,6 @@ jobs:
path: .ff
repository: filipeforattini/ff-iac-github-actions

- name: Load setup configs
env:
PIPELINE_SETUP: ${{ needs.Setup.outputs.PipelineConfig }}
id: deploy_setup
run: |
echo "::set-output name=deploy_as_k8s::$(echo $PIPELINE_SETUP | jq -r '.deploy.deployAsK8s')"
echo "::set-output name=deploy_as_chart::$(echo $PIPELINE_SETUP | jq -r '.deploy.deployAsChart')"
echo "::set-output name=deploy_ecossystem::$(echo $PIPELINE_SETUP | jq -r '.deploy.ecossystem')"
echo "::set-output name=deploy_organization::$(echo $PIPELINE_SETUP | jq -r '.deploy.organization')"
echo "::set-output name=deploy_container_registry::$(echo $PIPELINE_SETUP | jq -r '.deploy.containerRegistry')"
echo "::set-output name=deploy_repository::$(echo $PIPELINE_SETUP | jq -r '.deploy.repository')"
echo "::set-output name=deploy_tag::$(echo $PIPELINE_SETUP | jq -r '.deploy.tag')"
# deploy
- name: Install YTT
uses: vmware-tanzu/carvel-setup-action@v1
Expand All @@ -373,16 +363,18 @@ jobs:

- name: Generates Kubernetes YAML
if: steps.deploy_setup.outputs.deploy_as_k8s == 'true'
env:
PIPELINE_SETUP: ${{ steps.script_setup.outputs.result}}
run: |
ytt \
-f ./.ff/deploy/as-k8s/service.schema.yml \
-f ./.ff/deploy/as-k8s/service.yml \
-f ./manifests/k8s-values.yml \
--data-value ecossystem=${{steps.deploy_setup.outputs.deploy_ecossystem}} \
--data-value organization=${{steps.deploy_setup.outputs.deploy_organization}} \
--data-value containerRegistry=${{steps.deploy_setup.outputs.deploy_container_registry}} \
--data-value repository=${{steps.deploy_setup.outputs.deploy_repository}} \
--data-value tag=${{steps.deploy_setup.outputs.deploy_tag}} \
--data-value ecosystem=$(echo $PIPELINE_SETUP | jq -r '.deploy.ecosystem') \
--data-value organization=$(echo $PIPELINE_SETUP | jq -r '.deploy.organization') \
--data-value containerRegistry=$(echo $PIPELINE_SETUP | jq -r '.deploy.containerRegistry') \
--data-value repository=$(echo $PIPELINE_SETUP | jq -r '.deploy.repository') \
--data-value tag=$(echo $PIPELINE_SETUP | jq -r '.deploy.tag') \
> ./manifests/k8s-to-apply.yml
cat ./manifests/k8s-to-apply.yml
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This pipeline assumes you have just `3` types of repositories:

Those repositories must obey a name pattern.

`{ecossystem}-{type}-{name/client/integration}`
`{ecosystem}-{type}-{name/client/integration}`

Examples:

Expand Down
40 changes: 16 additions & 24 deletions deploy/as-k8s/service.schema.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,34 @@
#@data/values-schema

---
ecossystem: ff
organization: filipeforattini
ecosystem: acm
organization: acme
containerRegistry: ghcr.io
repository: ff-svc-repository
repository: acm-svc-repository
environment: dev
tag: latest

environment: dev
features:
enableLinkerd: true

namespace:
enable: true
annotations:
linkerd.io/inject: enabled
labels:
ff/ecossystem: ff
labels: {}
annotations: {}

deployment:
enable: true
replicas: 1
name: svc
port: 80

resources:
enable: false
claim:
limits:
memory: 512Mi
cpu: "1"
requests:
memory: 64Mi
cpu: "0.2"

annotations:
linkerd.io/inject: enabled

labels:
ff/ecossystem: ff
labels: {}
annotations: {}
resources: {}

templateLabels: {}
matchLabels:
overwrite: false
labels: {}

ingress:
enable: false
Expand Down
75 changes: 58 additions & 17 deletions deploy/as-k8s/service.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
#@ load("@ytt:data", "data")
#@ load("@ytt:md5", "md5")
#@ load("@ytt:sha256", "sha256")

#@ configHash = sha256.sum("data")
#@ configMD5 = md5.sum("data")
#@ configSHA256 = sha256.sum("data")

#@ globalLabels = {}
#@ globalLabels.update({ "ecosystem": data.values.ecosystem })

#@ globalAnnotations = {}
#@ globalAnnotations.update({ "pipe/ecosystem": data.values.ecosystem })
#@ globalAnnotations.update({ "pipe/config-md5": configMD5 })
#@ globalAnnotations.update({ "pipe/config-sha256": configSHA256 })

---
#@ if data.values.namespace.enable:
apiVersion: v1
kind: Namespace
metadata:
name: #@ data.values.repository
labels: #@ data.values.namespace.labels
annotations: #@ data.values.namespace.annotations

#@ namespaceLabels = {}
#@ namespaceLabels.update(data.values.namespace.labels)
#@ namespaceLabels.update(globalLabels)
labels: #@ namespaceLabels

#@ namespaceAnnotations = {}
#@ namespaceAnnotations.update(data.values.namespace.annotations)
#@ namespaceAnnotations.update(globalAnnotations)
#@ if data.values.features.enableLinkerd:
#@ namespaceAnnotations.update({ "linkerd.io/inject": "enabled" })
#@ end
annotations: #@ namespaceAnnotations
#@ end

---
Expand All @@ -24,10 +45,14 @@ metadata:
#@ else:
namespace: default
#@ end
annotations:
kubectl.kubernetes.io/last-applied-configuration: #@ configHash

#@ secretAnnotations = {}
#@ secretAnnotations.update(globalAnnotations)
#! kubectl.kubernetes.io/last-applied-configuration: #@ sha256
annotations: #@ secretAnnotations
data:
config: #@ configHash
config-md5: #@ configMD5
config-sha256: #@ configSHA256

---
#@ if data.values.deployment.enable:
Expand All @@ -40,25 +65,41 @@ metadata:
#@ else:
namespace: default
#@ end

#@ deploymentLabels = {}
#@ deploymentLabels.update(globalLabels)
#@ deploymentLabels.update(data.values.deployment.labels)
labels: #@ deploymentLabels

#@ deploymentAnnotations = {}
#@ deploymentAnnotations.update(globalAnnotations)
#@ deploymentAnnotations.update(data.values.deployment.annotations)
annotations: #@ deploymentAnnotations
spec:
replicas: #@ data.values.deployment.replicas
selector:
matchLabels:
ff/selector: #@ data.values.repository

#@ if data.values.deployment.matchLabels.overwrite:
matchLabels: #@ data.values.deployment.matchLabels.labels
#@ else:
#@ deploymentMatchLabels = {}
#@ deploymentMatchLabels.update({ "pipe/selector": data.values.repository })
matchLabels: #@ deploymentMatchLabels
#@ end
template:
metadata:
labels:
ff/ecossystem: #@ data.values.ecossystem
ff/selector: #@ data.values.repository
#@ deploymentTemplateLabels = {}
#@ deploymentTemplateLabels.update(globalLabels)
#@ deploymentTemplateLabels.update({ "pipe/ecosystem": data.values.ecosystem })
#@ deploymentTemplateLabels.update({ "pipe/selector": data.values.repository })
#@ deploymentTemplateLabels.update(data.values.deployment.templateLabels)
labels: #@ deploymentTemplateLabels
spec:
containers:
- name: #@ data.values.deployment.name
image: #@ "{}/{}/{}:{}".format(data.values.containerRegistry, data.values.organization, data.values.repository, data.values.tag)
imagePullPolicy: Always
#@ if/end data.values.deployment.resources.enable:
resources: #@ data.values.deployment.resources.claim
labels: #@ data.values.deployment.labels
annotations: #@ data.values.deployment.annotations
resources: #@ data.values.deployment.resources
env:
- name: DEBUG
value: "*"
Expand All @@ -84,8 +125,8 @@ metadata:
alb.ingress.kubernetes.io/success-codes: 200-399
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/ssl-policy: ELBSecurityPolicy-2016-08
alb.ingress.kubernetes.io/group.name: #@ data.values.ecossystem
alb.ingress.kubernetes.io/load-balancer-name: #@ data.values.ecossystem
alb.ingress.kubernetes.io/group.name: #@ data.values.ecosystem
alb.ingress.kubernetes.io/load-balancer-name: #@ data.values.ecosystem
alb.ingress.kubernetes.io/certificate-arn: #@ data.values.ingress.alb.certificateArn
#@ end
spec:
Expand Down
3 changes: 3 additions & 0 deletions src/scrappers/deploy.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module.exports = class Deploy extends Scrapper {
? 'iac'
: 'unknown'

const ecosystem = this.inputs.ecosystem || repository.split('-')[0]

const deployAsK8s = fs.existsSync(path.join(process.cwd(), 'manifests', 'k8s-values.yml'))
? true
: false
Expand All @@ -29,6 +31,7 @@ module.exports = class Deploy extends Scrapper {
})
.add('deploy', {
podName,
ecosystem,
deployAsK8s,
deployAsChart,
containerRegistry,
Expand Down

0 comments on commit 2cac572

Please sign in to comment.