Skip to content

Commit

Permalink
feat: added support for app deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipe Forattini committed Jul 26, 2022
1 parent 81dee39 commit 284eb1a
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 44 deletions.
18 changes: 18 additions & 0 deletions .github/actions/config-scrapper/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,26 @@ outputs:
description: ""
commiter_username:
description: ""
deploy_configs_file:
description: ""
deploy_secrets_file:
description: ""
deploy_dependencies_file:
description: ""
deploy_namespace:
description: ""
deploy_tag:
description: ""
event:
description: ""
environment:
description: ""
feature_has_configs:
description: ""
feature_has_secrets:
description: ""
feature_has_dependencies:
description: ""
feature_has_dockerfile:
description: ""
feature_has_dockerignore:
Expand All @@ -44,6 +58,10 @@ outputs:
description: ""
registry:
description: ""
repository:
description: ""
organization:
description: ""

runs:
using: "node16"
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/config-scrapper/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/actions/config-scrapper/index.js.map

Large diffs are not rendered by default.

45 changes: 12 additions & 33 deletions .github/workflows/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ jobs:
# namespace
- name: K8s create namespace
run: kubectl create namespace ${{steps.deploy_setup.outputs.deploy_namespace}} --dry-run=client --validate=false --output=yaml | kubectl apply -f -
run: kubectl create namespace ${{steps.analysis.outputs.deploy_namespace}} --dry-run=client --validate=false --output=yaml | kubectl apply -f -

# secrets for registry auth
- name: Config | Login to Container Registry
Expand All @@ -351,52 +351,31 @@ jobs:
password: ${{ secrets.REGISTRY_PASSWORD }}

- name: Config | Gives runner access to docker config file
if: steps.deploy_setup.outputs.deploy_as_k8s == 'true'
run: |
sudo chown $(whoami):docker /home/$(whoami)/.docker/config.json
cp /home/$(whoami)/.docker/config.json ./manifests/docker-config.json
- name: K8s create registry-token secret
if: steps.deploy_setup.outputs.deploy_as_k8s == 'true'
run: kubectl create secret generic -n ${{steps.deploy_setup.outputs.deploy_namespace}} registry-token --type=kubernetes.io/dockerconfigjson --from-file=.dockerconfigjson=./manifests/docker-config.json --dry-run=client --validate=false --output=yaml | kubectl apply -f -
run: kubectl create secret generic -n ${{steps.analysis.outputs.deploy_namespace}} registry-token --type=kubernetes.io/dockerconfigjson --from-file=.dockerconfigjson=./manifests/docker-config.json --dry-run=client --validate=false --output=yaml | kubectl apply -f -

# generate k8s manifests
- name: K8s generates final yml
if: steps.deploy_setup.outputs.deploy_as_k8s == 'true'
run: |
CONFIGS_LIST=$(if test -f ./manifests/k8s-configs-keys.txt; then cat ./manifests/k8s-configs-keys.txt; else echo ''; fi)
SECRETS_LIST=$(if test -f ./manifests/k8s-secrets-keys.txt; then cat ./manifests/k8s-secrets-keys.txt; else echo ''; fi)
DEPENDENCIES_LIST=$(if test -f ./manifests/k8s-dependencies.yml; then (cat ./manifests/k8s-dependencies.yml | yq -P '.dependencies'); else echo '' ; fi)
ytt \
-f ./.pipeline/deploy/as-k8s/app.schema.yml \
-f ./.pipeline/deploy/as-k8s/app.yml \
-f ./manifests/k8s-values.yml \
--data-value ecosystem=${{steps.deploy_setup.outputs.deploy_ecosystem}} \
--data-value organization=${{steps.deploy_setup.outputs.deploy_organization}} \
--data-value repository=${{steps.deploy_setup.outputs.deploy_repository}} \
--data-value containerRegistry=${{steps.deploy_setup.outputs.deploy_container_registry}} \
--data-value tag=${{steps.deploy_setup.outputs.deploy_tag}} \
--data-value-yaml deployment.imagePullSecrets=true \
--data-value pipelineControl.datetime=${{steps.deploy_setup.outputs.run_started_at}} \
--data-value-yaml pipelineControl.environmentsAsNamespaces=${{inputs.environmentsAsNamespaces}} \
-f ./manifests/k8s.yml \
--data-value ecosystem=${{steps.deploy_setup.outputs.deploy_ecosystem}} \
--data-value organization=${{steps.deploy_setup.outputs.deploy_organization}} \
--data-value repository=${{steps.deploy_setup.outputs.deploy_repository}} \
--data-value containerRegistry=${{steps.deploy_setup.outputs.deploy_container_registry}} \
--data-value tag=${{steps.deploy_setup.outputs.deploy_tag}} \
--data-value-yaml deployment.imagePullSecrets=true \
--data-value pipelineControl.datetime=${{steps.deploy_setup.outputs.run_started_at}} \
--data-value-yaml pipelineControl.environmentsAsNamespaces=${{inputs.environmentsAsNamespaces}} \
> ./manifests/k8s-to-apply.yml
- name: Docs | K8s summary
if: steps.deploy_setup.outputs.deploy_as_k8s == 'true'
run: |
CONFIGS_LIST=$(if test -f ./manifests/k8s-configs-keys.txt; then cat ./manifests/k8s-configs-keys.txt; else echo ''; fi)
SECRETS_LIST=$(if test -f ./manifests/k8s-secrets-keys.txt; then cat ./manifests/k8s-secrets-keys.txt; else echo ''; fi)
DEPENDENCIES_LIST=$(if test -f ./manifests/k8s-dependencies.yml; then (cat ./manifests/k8s-dependencies.yml | yq -P '.dependencies'); else echo ''; fi)
echo -e "### k8s\n\n" >> $GITHUB_STEP_SUMMARY
echo -e "| param | value |" >> $GITHUB_STEP_SUMMARY
echo -e "| --- | :---: |" >> $GITHUB_STEP_SUMMARY
echo -e "| secrets | $SECRETS_LIST |" >> $GITHUB_STEP_SUMMARY
echo -e "| configs | $CONFIGS_LIST |" >> $GITHUB_STEP_SUMMARY
echo -e "| dependencies | $DEPENDENCIES_LIST |" >> $GITHUB_STEP_SUMMARY
echo -e "<details><summary>kubefile</summary>\n\n\`\`\`yml \n$(cat ./manifests/k8s-to-apply.yml)\n \`\`\`\n </details>\n\n" >> $GITHUB_STEP_SUMMARY
- name: K8s apply yml
if: steps.deploy_setup.outputs.deploy_as_k8s == 'true'
run: |
kubectl apply -f ./manifests/k8s-to-apply.yml
kubectl get pods -n ${{steps.deploy_setup.outputs.deploy_namespace}}
kubectl get pods -o wide -n ${{steps.deploy_setup.outputs.deploy_namespace}}
2 changes: 1 addition & 1 deletion .github/workflows/svc-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ jobs:
ytt \
-f ./.pipeline/deploy/as-k8s/service.schema.yml \
-f ./.pipeline/deploy/as-k8s/service \
-f ./manifests/k8s-values.yml \
-f ./manifests/k8s.yml \
--data-value ecosystem=${{steps.deploy_setup.outputs.deploy_ecosystem}} \
--data-value organization=${{steps.deploy_setup.outputs.deploy_organization}} \
--data-value repository=${{steps.deploy_setup.outputs.deploy_repository}} \
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ stateDiagram-v2
│ │ └─ dev.yml
│ ├─ secrets
│ │ └─ dev.gpg
│ ├─ k8s-values.yml
│ └─ helm-values.yml
│ ├─ k8s.yml
│ └─ helm.yml
├─ dist
│ // distibuition version of our code
└─ src
Expand Down
18 changes: 18 additions & 0 deletions src/actions/config-scrapper/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,26 @@ outputs:
description: ""
commiter_username:
description: ""
deploy_configs_file:
description: ""
deploy_secrets_file:
description: ""
deploy_dependencies_file:
description: ""
deploy_namespace:
description: ""
deploy_tag:
description: ""
event:
description: ""
environment:
description: ""
feature_has_configs:
description: ""
feature_has_secrets:
description: ""
feature_has_dependencies:
description: ""
feature_has_dockerfile:
description: ""
feature_has_dockerignore:
Expand All @@ -44,6 +58,10 @@ outputs:
description: ""
registry:
description: ""
repository:
description: ""
organization:
description: ""

runs:
using: "node16"
Expand Down
4 changes: 2 additions & 2 deletions src/actions/config-scrapper/scrappers/deploy.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module.exports = class Deploy extends Scrapper {

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

const deployAsK8s = fs.existsSync(path.join(process.cwd(), 'manifests', 'k8s-values.yml'))
const deployAsChart = fs.existsSync(path.join(process.cwd(), 'manifests', 'charts-values.yml'))
const deployAsK8s = fs.existsSync(path.join(process.cwd(), 'manifests', 'k8s.yml'))
const deployAsChart = fs.existsSync(path.join(process.cwd(), 'manifests', 'helm.yml'))

let envs = [ 'dev', 'stg', 'prd', 'sbx', 'dry' ]

Expand Down
29 changes: 29 additions & 0 deletions src/actions/config-scrapper/src/deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,35 @@ module.exports = async (analysis) => {
analysis.deployment.labelsString = labels.join(', ')
core.info(templateInfo('deployment', `labels = ${labels}`))


if (github.context.payload.deployment) {
// k8s
analysis.deployment.namespace = `${name}-${analysis.environment}`
analysis.outputs.deploy_namespace = analysis.deployment.namespace

const configsFilePath = path.join(analysis.root, 'manifests', 'configs', `${analysis.environment}.env`)
const secretsFilePath = path.join(analysis.root, 'manifests', 'secrets', `${analysis.environment}.gpg`)
const dependenciesFilePath = path.join(analysis.root, 'manifests', 'dependencies', `${analysis.environment}.yml`)

if(fs.existsSync(configsFilePath)) {
analysis.deployment.configsFile = configsFilePath
analysis.outputs.deploy_configs_file = configsFilePath
analysis.outputs.feature_has_configs = true
}

if(fs.existsSync(secretsFilePath)) {
analysis.deployment.secretsFile = secretsFilePath
analysis.outputs.deploy_secrets_file = secretsFilePath
analysis.outputs.feature_has_secrets = true
}

if(fs.existsSync(dependenciesFilePath)) {
analysis.deployment.dependenciesFile = dependenciesFilePath
analysis.outputs.deploy_dependencies_file = dependenciesFilePath
analysis.outputs.feature_has_dependencies = true
}
}

// outputs
analysis.outputs.registry = analysis.deployment.registry
analysis.outputs.deploy_tag = analysis.deployment.tag
Expand Down
3 changes: 0 additions & 3 deletions src/actions/config-scrapper/src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@ module.exports = async (analysis) => {
analysis.outputs.commiter_email = analysis.commiter.email
analysis.outputs.commiter_username = analysis.commiter.username
}

// outputs
analysis.outputs.event = analysis.event
}
2 changes: 1 addition & 1 deletion src/scrappers/deploy.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = class Deploy extends Scrapper {

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

const deployAsK8s = fs.existsSync(path.join(process.cwd(), 'manifests', 'k8s-values.yml'))
const deployAsK8s = fs.existsSync(path.join(process.cwd(), 'manifests', 'k8s.yml'))
const deployAsChart = fs.existsSync(path.join(process.cwd(), 'manifests', 'charts-values.yml'))

let envs = [ 'dev', 'stg', 'prd', 'sbx', 'dry' ]
Expand Down
12 changes: 12 additions & 0 deletions test/assets/app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#@data/values
---
port: 80

env:
- name: TZ
value: America/Sao_Paulo

#! ingress:
#! enable: true
#! type: traefik
#!
6 changes: 6 additions & 0 deletions test/cases/app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#/bin/sh
ytt \
-f $DIR_SRC/service.schema.yml \
-f $DIR_SRC/service \
-f $DIR_ASSETS/app.yml \
> $DIR_RESULTS/app.yml
2 changes: 2 additions & 0 deletions test/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export DIR_RESULTS=${DIR_RESULTS:-"./tmp"}
sh $DIR_TESTS/svc.sh
sh $DIR_TESTS/svc-inputs.sh
sh $DIR_TESTS/svc-service.sh

sh $DIR_TESTS/app.sh

0 comments on commit 284eb1a

Please sign in to comment.