Skip to content

Commit dcd70fd

Browse files
authored
shell script for running emulator with options pulled from environment vars (#84)
* add optional entrypoint * include sh file
1 parent 903e095 commit dcd70fd

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ COPY go.mod go.sum ./
77
RUN go mod download
88

99
COPY . .
10-
1110
RUN go build -o emulator .
1211

13-
1412
FROM alpine:latest
1513

1614
LABEL org.opencontainers.image.source=https://github.com/aertje/cloud-tasks-emulator
1715

18-
ENTRYPOINT ["/emulator"]
19-
2016
WORKDIR /
2117

2218
COPY --from=builder /app/emulator .
19+
COPY --from=builder /app/emulator_from_env.sh .
20+
RUN chmod +x emulator_from_env.sh
21+
22+
ENTRYPOINT ["./emulator"]

emulator_from_env.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
3+
RUN_CMD="/emulator"
4+
5+
if [ -n "$HOST" ]; then
6+
RUN_CMD="$RUN_CMD -host=$HOST"
7+
fi
8+
9+
if [ -n "$PORT" ]; then
10+
RUN_CMD="$RUN_CMD -port=$PORT"
11+
fi
12+
13+
if [ -n "$HARD_RESET_ON_PURGE_QUEUE" ]; then
14+
RUN_CMD="$RUN_CMD -hard_reset_on_purge_queue=$HARD_RESET_ON_PURGE_QUEUE"
15+
fi
16+
17+
if [ -n "$OPENID_ISSUER" ]; then
18+
RUN_CMD="$RUN_CMD -openid_issuer=$OPENID_ISSUER"
19+
fi
20+
21+
if [ -n "$INITIAL_QUEUES" ]; then
22+
IFS=","
23+
set -- $INITIAL_QUEUES
24+
for i in "$@"; do
25+
RUN_CMD="$RUN_CMD -queue=$i"
26+
done
27+
fi
28+
29+
`$RUN_CMD`

readme.MD

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ go run ./ -host localhost \
3535
-queue projects/dev/locations/here/queues/anotherq
3636
```
3737

38+
Alternatively, you can define environment variables and then run the shell script `./emulator_from_env.sh` to start the emulator. The following environment variables are supported:
39+
40+
```sh
41+
export PORT=8124
42+
export HOST=localhost
43+
export HARD_RESET_ON_PURGE=true
44+
export INITIAL_QUEUES=projects/dev/locations/here/queues/1,projects/dev/locations/here/queues/2
45+
export OPENID_ISSUER=http://localhost:8080
46+
47+
./emulator_from_env.sh
48+
```
49+
3850
Once running, you connect to it using the standard google cloud tasks GRPC libraries.
3951

4052
### Docker
@@ -64,7 +76,7 @@ gcloud-tasks-emulator:
6476
6577
6678
## App Engine
67-
If you want to use it to make calls to a local [App Engine emulator](https://cloud.google.com/appengine/docs/standard/python3/testing-and-deploying-your-app#local-dev-server) instance, you'll need to set the appropriate environment variable, e.g.:
79+
If you want to use it to make calls to a local [App Engine emulator](https://cloud.google.com/appengine/docs/standard/python3/testing-and-deploying-your-app#local-dev-server) instance, you'll need to set the appropriate environment variable, e.g.:
6880
```sh
6981
export APP_ENGINE_EMULATOR_HOST=http://localhost:8080
7082
```
@@ -216,7 +228,7 @@ $client = new CloudTasksClient([
216228
]
217229
]
218230
]);
219-
231+
220232
$http = new HttpRequest();
221233
$http->setHttpMethod(HttpMethod::GET)->setUrl('https://google.com');
222234

0 commit comments

Comments
 (0)