generated from oracle-devrel/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init - this is a direct copy over from https://github.com/oracle/micr…
- Loading branch information
1 parent
f7d68f0
commit 48ee2d3
Showing
1,613 changed files
with
385,932 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
_Copyright (c) 2019, 2020, 2021 Oracle and/or its affiliates The Universal Permissive License (UPL), Version 1.0_ | ||
|
||
# Deployment Functions | ||
|
||
The deployment helper functions are defined in common/utils/deploy-functions.env and sourced by common/source.env. They are used to streamline the deployment of microservices. | ||
|
||
## k8s_deploy | ||
|
||
Deploy a set of yaml files. The function accepts a single parameter that represents a space separate list of yaml files to be deployed, for example: | ||
|
||
``` | ||
k8s-deploy 'inventory-helidon-deployment.yaml inventory-service.yaml' | ||
``` | ||
|
||
### Internals | ||
|
||
kubectl apply is used to deploy the files and so the k8s_deploy function is idempotent. | ||
|
||
The yaml files are expected to be in the same folder as the script that invokes this function. | ||
|
||
The yaml files are processed to substitute environment variables before they are deployed. The processed yaml files are place in the .deployed folder in the home directory of the microservice. | ||
|
||
The syntax available to define substitution variable is as follows: | ||
|
||
- **${VAR}** Fails if VAR is undefined, else is substitutes the value of VAR | ||
- **${VAR-default}** If VAR is not defined substitute 'default', else substitutes the value of VAR | ||
- **${VAR-}** If VAR is not defined substitute '', else it substitutes the value of VAR | ||
- **${VAR?MSG}** Fails if VAR is undefined with the error 'MSG', else it substitutes value of VAR | ||
- **${VAR:-default}** If VAR is not defined or empty, substitute 'default', else it substitutes the value of VAR | ||
- **${VAR:?MSG}** Fails if VAR is undefined or empty with the error 'MSG', else it substitutes the value of VAR | ||
|
||
Here is an example: | ||
|
||
``` | ||
- name: OCI_REGION | ||
value: "${OCI_REGION-}" | ||
``` | ||
|
||
## k8s_undeploy | ||
|
||
Undeploy the yaml files what were deployed by k82_deploy. The files are undeployed in the reverse order. | ||
|
||
### Internals | ||
|
||
The yaml files of the deployed resources are found in the .deployed folder. The files are deleted once thay have been undeployed. | ||
|
||
kubectl delete is used to undeploy the resources. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2021 Oracle and/or its affiliates. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. | ||
|
||
# Make sure this is run via source or . | ||
if ! (return 0 2>/dev/null); then | ||
echo "ERROR: Usage 'source source.env'" | ||
return 1 | ||
fi | ||
|
||
export MSDD_CODE="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )" | ||
export MSDD_INFRA_CODE="$MSDD_CODE/infra" | ||
export MSDD_APPS_CODE="$MSDD_CODE" | ||
export MSDD_WORKSHOP_CODE="$MSDD_CODE/workshops" | ||
|
||
source $MSDD_CODE/common/utils/provisioning-functions.env | ||
source $MSDD_CODE/common/utils/deploy-functions.env | ||
source $MSDD_CODE/common/utils/setup-functions.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2021 Oracle and/or its affiliates. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. | ||
|
||
|
||
if ! (return 0 2>/dev/null); then | ||
echo "ERROR: Usage 'source deploy_functions.env'" | ||
return 1 | ||
fi | ||
|
||
|
||
# k8s-deploy | ||
# Deploy a microservice | ||
# $1: Space separated list of files to be deployed (in order of deployment) | ||
# | ||
function k8s-deploy() { | ||
# Fail on error or inadvertently referencing undefined variables | ||
set -eu | ||
|
||
# Locate the script directory. All the files are there. | ||
local SCRIPT_DIR=$(dirname "$0") | ||
if ! test -d $SCRIPT_DIR; then | ||
echo "ERROR: Script directory does not exist" | ||
return 1 | ||
fi | ||
|
||
# First parameter is required | ||
local DEPLOYMENT_FILES="$1" | ||
|
||
local DEPLOYED_DIR=$SCRIPT_DIR/.deployed | ||
|
||
local df | ||
for df in $DEPLOYMENT_FILES; do | ||
echo "Applying $df" | ||
mkdir -p $DEPLOYED_DIR | ||
|
||
# Expand the deployment file into the deployed directory | ||
eval "cat >$DEPLOYED_DIR/$df <<! | ||
$(<$SCRIPT_DIR/$df) | ||
! | ||
" | ||
|
||
# Apply | ||
kubectl apply -f $DEPLOYED_DIR/$df -n msdataworkshop | ||
done | ||
} | ||
|
||
|
||
# k8s-undeploy | ||
# Undeploy k8s resources previously deployed by k8s_deploy | ||
# | ||
function k8s-undeploy() { | ||
# Fail on error or inadvertently referencing undefined variables | ||
set -eu | ||
|
||
# Locate the script directory. All the files are there. | ||
local SCRIPT_DIR=$(dirname "$0") | ||
if ! test -d $SCRIPT_DIR; then | ||
echo "ERROR: Script directory does not exist" | ||
return 1 | ||
fi | ||
|
||
local DEPLOYED_DIR=$SCRIPT_DIR/.deployed | ||
if ! test -d $DEPLOYED_DIR; then | ||
# Nothing deployed and so noting to do | ||
return 0 | ||
fi | ||
cd $DEPLOYED_DIR | ||
|
||
local df | ||
for df in $(ls -r); do | ||
echo "Deleting $df" | ||
# Delete | ||
kubectl delete -f $df -n msdataworkshop | ||
rm $df | ||
done | ||
} | ||
|
||
export -f k8s-deploy | ||
export -f k8s-undeploy |
Oops, something went wrong.