Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
perekopskiy committed Aug 11, 2021
2 parents 2dc2bee + f68a00b commit b5131d9
Show file tree
Hide file tree
Showing 140 changed files with 1,972 additions and 6,456 deletions.
12 changes: 12 additions & 0 deletions .github/scripts/write-kubeconf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

confVar="$1"
mkdir -p ~/.kube &> /dev/null

if [ -n "$confVar" ]; then
read KUBECONF <<< $(eval echo \$$confVar)
else
: ${KUBECONF?KUBECONF or envvar name must be provided}
fi

echo $KUBECONF | base64 -d > ~/.kube/config
109 changes: 109 additions & 0 deletions .github/scripts/zksync-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/bash
## This script updates server-env-custom (merges the etc/env/xxx file with configmap)
# loadtest (without parameters) - combined env
# --repo [loadtest] - env from file
# --kube [loadtest] - env from configmap
# --diff [loadtest] - show the diff to be applied to the configmap
# --merge [loadtest] - writes merged configmap with merged env values
# --update-from fromfile [loadtest] - updates loadtestet env with values fromfile
# --diff-from fromfile [loadtest] - show diff for loadtestet env with values fromfile

set -e

serverEnv="server-env-custom"
repoRoot=`cd $( dirname "${BASH_SOURCE[0]}" )/../.. >/dev/null 2>&1 && pwd`

cmd="$1"
opts=""

if ( echo "--update-from --diff-from" | grep -qw "\\$cmd" ); then
fromfile="$2"
namespace="${ZKSYNC_ENV:-$3}"
else
namespace="${ZKSYNC_ENV:-$2}"
fi

[ -z $namespace ] || opts="$opts -n $namespace"

kube_env() {
if ( kubectl $opts get cm $serverEnv &> /dev/null ); then
kubectl $opts get cm $serverEnv -o go-template --template='{{ range $k,$v := .data}}{{ printf "%s=%s" $k $v }}{{"\n"}}{{end}}'
fi
}

##
repo_env() {
. $repoRoot/etc/env/$namespace.env
export $(cut -d= -f1 etc/env/$namespace.env | sed -r '/^\s*#/d')
env | sed "/^\($1\)/d"
}

cmDiff() {
kubectl $opts create cm $serverEnv --from-env-file="$tmpfile" --dry-run -o yaml | kubectl diff -f - || :
}

cleanup() {
if [ -n "$tmpfile" ]; then
rm -f "$tmpfile"
fi
}

trap cleanup EXIT

## We call ourself - carefull!
case $cmd in
--kube)
kube_env
;;
--repo)
# current env to sanitize
sanitize=$(env | cut -d= -f1 | sed ':a;N;$!ba;s/\n/\\\|/g')
repo_env "$sanitize"
;;
--diff)
tmpfile=$(mktemp -u)
bash $0 $2 > "$tmpfile"
cmDiff
;;
--merge)
tmpfile=$(mktemp -u)
bash $0 $2 > "$tmpfile"

# overwrites configmap!
outp=$(cmDiff)
if ( echo "$outp" | grep -Fq '+++' ); then
kubectl $opts create cm $serverEnv --from-env-file="$tmpfile" --dry-run -o yaml | \
kubectl apply -f -
elif [ -n "$outp" ]; then
# write a error (since no diff)
echo $outp
exit 2
fi
;;
--update-from)
tmpfile=$(mktemp -u)
{ cat $fromfile; bash $0 --kube $namespace; } | sort -u -t '=' -k 1,1 > "$tmpfile"

# overwrites configmap!
outp=$(cmDiff)
if ( echo "$outp" | grep -Fq '+++' ); then
kubectl $opts create cm $serverEnv --from-env-file="$tmpfile" --dry-run -o yaml | \
kubectl apply -f -
elif [ -n "$outp" ]; then
# write a error (since no diff)
echo $outp
exit 2
fi
;;
--diff-from)
tmpfile=$(mktemp -u)
{ cat $fromfile; bash $0 --kube $namespace; } | sort -u -t '=' -k 1,1 > "$tmpfile"
cmDiff
;;
*)
# Combine two outputs.
# We favour output from kube!
#
{ bash $0 --kube $1; bash $0 --repo $1; } | sort -u -t '=' -k 1,1
;;
esac
162 changes: 0 additions & 162 deletions .github/workflows/deploy-apps.yml

This file was deleted.

72 changes: 72 additions & 0 deletions .github/workflows/deploy-chat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Deploy from Chat

on:
deployment:

defaults:
run:
shell: bash -leo pipefail {0}

# Disable simultaneous deployments into a single environment
concurrency: deploy-chat-${{ github.event.inputs.environment }}

jobs:
setup:
name: Setup
runs-on: [k8s, stage]
outputs:
image_tag: ${{ steps.set.outputs.shortRev }}
config_tag: ${{ steps.latest.outputs.tag }}
steps:
- uses: actions/checkout@v2
-
uses: actions-ecosystem/action-regex-match@v2
id: regex
with:
text: ${{ github.event.deployment.ref }}
regex: '^(v\d+\.\d+\.\d+)(-r\d+)?$'
-
uses: dysnix/find-latest-tag@v1
if: steps.regex.outputs.match != ''
id: latest
with:
regex: ${{ steps.regex.outputs.group1 }}(-r\d+)?
token: ${{ secrets.GH_TOKEN }}
repository: matter-labs/configs
-
id: set
run: |
echo "::set-output name=shortRev::$(git rev-parse --short HEAD)"
-
name: Check tag matches pattern
if: steps.regex.outputs.match == ''
uses: chrnorm/deployment-status@releases/v1
with:
token: ${{ github.token }}
state: failure
deployment_id: ${{ github.event.deployment.id }}
-
if: steps.regex.outputs.match == ''
run: |
echo "::error::Provided ref/tag doesn't match pattern!"
exit 1
deploy:
name: Deploy environment
runs-on: [k8s, stage]
needs: [setup]
steps:
- name: Deploy
uses: aurelien-baudet/workflow-dispatch@v2
with:
workflow: Deploy
token: ${{ secrets.GH_TOKEN }}
wait-for-completion-timeout: 10m
wait-for-completion-interval: 1m
inputs: |
{
"environment": "${{ github.event.deployment.environment }}",
"image_tag": "${{ needs.setup.outputs.image_tag }}",
"config_ref": "${{ needs.setup.outputs.config_tag }}",
"deployment_id": "${{ github.event.deployment.id }}"
}
6 changes: 6 additions & 0 deletions .github/workflows/deploy-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ on:
branches:
- dev
- breaking
- hotfix/*
tags:
- hotfix-*

# Disable simultaneous deployments into stage
concurrency: deploy-stage

jobs:
setup:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-zksync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defaults:
shell: bash -leo pipefail {0}

# Disable simultaneous deployments into a single environment
concurrency: deploy-${{ github.event.inputs.environment }}
concurrency: deploy-zksync-${{ github.event.inputs.environment }}

jobs:
setup:
Expand Down
Loading

0 comments on commit b5131d9

Please sign in to comment.