Skip to content

Commit 247fba3

Browse files
rmoffgunnarmorling
andauthored
Sample Dockerfile for the CLI (#22)
* Sample Dockerfile for the CLI * Add declarative example * Update cli-docker/README.adoc Co-authored-by: Gunnar Morling <gunnar.morling@googlemail.com> * Update image to include a way to generate refresh token too * typo * Update cli-docker/entrypoint.sh Co-authored-by: Gunnar Morling <gunnar.morling@googlemail.com> --------- Co-authored-by: Gunnar Morling <gunnar.morling@googlemail.com>
1 parent 5b48cc4 commit 247fba3

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ _Decodable provides a managed PyFlink service. Learn more [here](https://docs.de
8585
|-------------------------------------------------------|-------------|
8686
| [Flink SQL Troubleshooting](troubleshooting-flinksql) | A set of Docker Compose environments for demonstrating various Flink SQL troubleshooting scenarios (see [related blog](https://www.decodable.co/blog/flink-sql-misconfiguration-misunderstanding-and-mishaps?utm_medium=github&utm_source=examples_repo&utm_campaign=blog&utm_content=troubleshooting-flinksql))|
8787

88+
### Decodable tools
89+
90+
| Example | Description |
91+
|-------------------------------------------------------|-------------|
92+
| [Decodable CLI Docker image](cli-docker) | An example Dockerfile for running the Decodable CLI under Docker.|
93+
8894
## License
8995

9096
This code base is available under the Apache License, version 2.

cli-docker/Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM amd64/ubuntu:latest
2+
3+
# Set environment variables
4+
ENV DECO_CLI_VERSION=1.20.0
5+
ENV DECO_CLI_URL=https://releases.decodable.co/decodable-cli/linux/amd64/decodable-cli-linux-amd64-${DECO_CLI_VERSION}.tar.gz
6+
7+
# Install necessary packages
8+
RUN apt-get update && \
9+
apt-get install -y curl tar && \
10+
rm -rf /var/lib/apt/lists/*
11+
12+
# Download and unpack the Decodable CLI
13+
RUN curl -L $DECO_CLI_URL -o /tmp/decodable-cli.tar.gz && \
14+
tar -xzf /tmp/decodable-cli.tar.gz -C /tmp && \
15+
mv /tmp/decodable-cli-linux-amd64-${DECO_CLI_VERSION}/bin/decodable /usr/local/bin && \
16+
rm -r /tmp/decodable-cli.tar.gz /tmp/decodable-cli-linux-amd64-${DECO_CLI_VERSION}
17+
18+
# Copy the entrypoint script into the image
19+
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
20+
21+
# Make the entrypoint script executable
22+
RUN chmod +x /usr/local/bin/entrypoint.sh
23+
24+
# Verify installation
25+
RUN decodable --version
26+
27+
# Set entrypoint
28+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

cli-docker/README.adoc

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
= Example container image for Decodable CLI
2+
3+
The https://docs.decodable.co/cli.html[Decodable CLI] enables you configure, view, and control resources on your Decodable account.
4+
5+
== Build
6+
7+
[source,bash]
8+
----
9+
cd cli-docker
10+
docker build -t decodable-cli .
11+
----
12+
13+
== Usage
14+
15+
You need two configuration values:
16+
17+
* Your Decodable **account name**
18+
* The **refresh token** for your account. You can obtain this by running the Docker image with the `print-refresh-token` argument:
19+
+
20+
[source,bash]
21+
----
22+
docker run --rm -it \
23+
-e DECODABLE_ACCOUNT_NAME=<your account id> \
24+
decodable-cli:latest \
25+
print-refresh-token
26+
----
27+
+
28+
You'll be prompted to open a URL in your web browser which will take you through the Decodable authentication process.
29+
After entering the supplied values you'll get a refresh token.
30+
+
31+
WARNING: Anyone with refresh token can access your Decodable account.
32+
Treat your refresh token as you would any other sensitive information such as passwords.
33+
If you invoke the Docker container as illustrated below note that the refresh token will remain on your command line history and thus be vulnerable to local access.
34+
35+
=== Invocation
36+
37+
[source,bash]
38+
----
39+
docker run --rm \
40+
-e DECODABLE_ACCOUNT_NAME=<your account id> \
41+
-e DECODABLE_REFRESH_TOKEN=<your refresh token> \
42+
decodable-cli:latest \
43+
<decodable CLI command line arguments>
44+
----
45+
46+
For example:
47+
48+
* Get CLI version
49+
+
50+
[source,bash]
51+
----
52+
docker run --rm \
53+
-e DECODABLE_ACCOUNT_NAME=<your account id> \
54+
-e DECODABLE_REFRESH_TOKEN=<your refresh token> \
55+
decodable-cli:latest \
56+
--version
57+
----
58+
59+
Show status of all resources
60+
+
61+
[source,bash]
62+
----
63+
docker run --rm \
64+
-e DECODABLE_ACCOUNT_NAME=<your account id> \
65+
-e DECODABLE_REFRESH_TOKEN=<your refresh token> \
66+
decodable-cli:latest \
67+
query --no-spec
68+
----
69+
70+
* Create and populate a secret "postgres-prod"
71+
+
72+
[source,bash]
73+
----
74+
# Create the resource definition
75+
# Ref: https://docs.decodable.co/declarative/definitions.html#secret
76+
cat <<EOF > postgres-prod.yaml
77+
---
78+
kind: secret
79+
metadata:
80+
name: postgres-prod
81+
description: 🤫 The password for the Production Postgres server
82+
spec_version: v1
83+
spec:
84+
value_file: ./pg_pw.txt
85+
EOF
86+
87+
# Write the password to a file, which is read when
88+
# the resource is created
89+
cat <<EOF > pg_pw.txt
90+
hunter2
91+
EOF
92+
93+
# Invoke the Decodable `apply` command
94+
# Ref: https://docs.decodable.co/declarative/apply.html#_how_to_use_the_apply_command
95+
docker run --rm \
96+
-e DECODABLE_ACCOUNT_NAME=<your account id> \
97+
-e DECODABLE_REFRESH_TOKEN=<your refresh token> \
98+
-v $PWD:/data \
99+
decodable-cli:latest \
100+
apply /data/postgres-prod.yaml
101+
----

cli-docker/entrypoint.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
# write the config file if env var set
4+
if [ -n "$DECODABLE_ACCOUNT_NAME" ]; then
5+
mkdir -p ~/.decodable
6+
cat <<EOF > ~/.decodable/config
7+
version: 1.0.0
8+
active-profile: default
9+
10+
profiles:
11+
default:
12+
account: $DECODABLE_ACCOUNT_NAME
13+
EOF
14+
else
15+
echo "\n⚠️ DECODABLE_ACCOUNT_NAME not set.\n"
16+
exit 1
17+
fi
18+
19+
# write the auth file if env var set
20+
if [ -n "$DECODABLE_REFRESH_TOKEN" ]; then
21+
mkdir -p ~/.decodable
22+
cat <<EOF > ~/.decodable/auth
23+
version: 1.0.0
24+
tokens:
25+
default:
26+
refresh_token: $DECODABLE_REFRESH_TOKEN
27+
EOF
28+
fi
29+
30+
# Execute the main process
31+
if [ "$1" = "print-refresh-token" ]; then
32+
decodable login
33+
echo "Refresh token: $(decodable token refresh)"
34+
else
35+
if [ -n "$DECODABLE_REFRESH_TOKEN" ]; then
36+
exec decodable "$@"
37+
else
38+
echo "\n⚠️ DECODABLE_REFRESH_TOKEN not set.\n👉 Use print-refresh-token to generate a refresh token.\n"
39+
exit 1
40+
fi
41+
fi

0 commit comments

Comments
 (0)