forked from IBM/CodeEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Doug Davis <[email protected]>
- Loading branch information
Doug Davis
committed
Oct 6, 2020
1 parent
86d9608
commit 69a0ebe
Showing
13 changed files
with
118 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
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
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
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,8 @@ | ||
FROM golang:alpine | ||
COPY mapenv.go / | ||
RUN go build -o /mapenv /mapenv.go | ||
|
||
# Copy the exe into a smaller base image | ||
FROM alpine | ||
COPY --from=0 /mapenv /mapenv | ||
CMD /mapenv |
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,12 @@ | ||
# MapEnv | ||
|
||
This sample shows how inject a secret and a configMap into an application | ||
as a set of environment variables. Secrets and ConfigMaps are both key/value | ||
pair objects - except secrets' data are protected/encrypted at rest. Which | ||
makes them a great choice for private data such as credentials or passwords. | ||
|
||
In both cases, the "key" of the secret/configMap will become the "name" of | ||
the environment variable and the corresponding "value" in the secret/configMap | ||
will be the "value" of that environment variable. | ||
|
||
The application will log (print to stdout) all of its environment variables. |
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,13 @@ | ||
#!/bin/bash | ||
|
||
# Env Vars: | ||
# REPOSITORY: name of the image registry/namespace to store the images | ||
|
||
set -ex | ||
export REPOSITORY=${REPOSITORY:-ibmcom} | ||
|
||
# Build the image | ||
docker build -t ${REPOSITORY}/mapenv . | ||
|
||
# And push it | ||
docker push ${REPOSITORY}/mapenv |
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,25 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"sort" | ||
) | ||
|
||
func main() { | ||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
// Sort the env vars | ||
envs := os.Environ() | ||
sort.Strings(envs) | ||
|
||
// And print them | ||
fmt.Printf("Environment variables - look for the ones with MY_") | ||
for _, e := range envs { | ||
fmt.Printf("%s\n", e) | ||
} | ||
}) | ||
|
||
fmt.Printf("Listening on port 8080\n") | ||
http.ListenAndServe(":8080", nil) | ||
} |
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,46 @@ | ||
#!/bin/bash | ||
|
||
# Env Vars: | ||
# REPOSITORY: name of the image registry/namespace to get the images | ||
|
||
# Clean up previous run | ||
function clean() { | ||
set +x | ||
echo Cleaning... | ||
ic ce app delete -n mapenv -f --wto=0 > /dev/null 2>&1 || true | ||
ic ce secret delete -n mysecret -f > /dev/null 2>&1 || true | ||
ic ce configmap delete -n myconfig -f > /dev/null 2>&1 || true | ||
rm -f out | ||
} | ||
|
||
clean | ||
[[ "$1" == "clean" ]] && exit 0 | ||
|
||
set -ex | ||
export REPOSITORY=${REPOSITORY:-ibmcom} | ||
|
||
# Create a Secret and a ConfigMap | ||
ic ce secret create --name mysecret --from-literal MY_SECRET_APIKEY=letmein | ||
ic ce configmap create --name myconfig --from-literal MY_CONFIG_KNOB=42 | ||
|
||
# Create the app | ||
ic ce app create -n mapenv --image ${REPOSITORY}/mapenv \ | ||
--env-from-secret mysecret --env-from-configmap myconfig | ||
|
||
# Get the URL of the app for later use | ||
URL=$(ic ce app get -n mapenv -o jsonpath={.status.url}) | ||
|
||
# Just force it to log something by hitting ig | ||
curl -Ls $URL | ||
|
||
# Extract the instance name from `ic ce app get` | ||
ic ce app get -n mapenv | tee out | ||
name=$(grep "mapenv.*Running" out | tail -1 | sed "s/ [12].*//") | ||
echo Instance name: $name | ||
|
||
# Now wait check the logs to see if the env vars were set | ||
ic ce app logs --instance $name | tee out | ||
grep MY_ out | ||
|
||
# Clean up | ||
clean |
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
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
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