Skip to content

Commit

Permalink
chore: ipython shell in a Docker container
Browse files Browse the repository at this point in the history
Initial support for running ipython shell as a docker compose service
that connects to other services running locally.
  • Loading branch information
ibukanov committed Jul 3, 2024
1 parent 435d166 commit 76ce948
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 106 deletions.
39 changes: 33 additions & 6 deletions docker-compose.payments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ services:
image: redis:7.0
restart: always
#ports:
# - '6379:6379'
command: redis-server --save 20 1 --loglevel verbose --requirepass testpass --user redis
# - '6380:6380'
command: redis-server --save 20 1 --loglevel verbose --requirepass testpass --user redis --port 6380
#volumes:
# - redis-cache:/data

Expand All @@ -17,7 +17,7 @@ services:
localstack:
container_name: localstack
image: localstack/localstack
stop_grace_period: 1s
stop_grace_period: "1s"
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
Expand All @@ -31,10 +31,10 @@ services:

worker:
image: bat-go-local
command: /build/bat-go serve payments worker
depends_on:
- redis
- localstack
command: /build/bat-go serve payments worker
environment:
- NITRO_ENCLAVE_MOCKING=1
- REDIS_ADDR=redis:6379
Expand All @@ -46,9 +46,12 @@ services:

service:
image: bat-go-local
command: /build/bat-go serve nitro inside-enclave --egress-address none --log-address none --upstream-url http://0.0.0.0:8080
depends_on:
- redis
- localstack
volumes:
- ./payments-test-secretes.json:/etc/bat-test-secretes.json:ro
command: /build/bat-go serve nitro inside-enclave --egress-address none --log-address none --upstream-url http://0.0.0.0:8080
environment:
- NITRO_ENCLAVE_MOCKING=1
- DEBUG=1
Expand All @@ -58,7 +61,7 @@ services:
- QLDB_LEDGER_ARN=arn:aws:qldb:us-west-2:239563960694:ledger/testing-igor-payment
- QLDB_LEDGER_NAME=testing-igor-payment
- QLDB_ROLE_ARN=arn:aws:iam::239563960694:role/settlements-dev-sso-qldb-20240628161845683100000001
- AWS_REGION=${AWS_REGION-}
- AWS_REGION=${AWS_REGION-us-west-2}
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID-}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY-}
- AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN-}
Expand All @@ -69,6 +72,30 @@ services:
- "127.0.0.1:18080:18080"
- "127.0.0.1:18443:18443"

shell:
image: bat-go-local
depends_on:
- redis
- localstack
# The shell uses localhost
network_mode: "service:redis"
command: ipython3 --profile-dir=ipython-profile
working_dir: /build/src/tools/payments
stdin_open: true
tty: true
environment:
- NITRO_ENCLAVE_MOCKING=1
- DEBUG=1
- REDIS_ADDR=redis:6379
- REDIS_USERNAME=default
- REDIS_PASSWORD=testpass
- AWS_REGION=${AWS_REGION-us-west-2}
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID-}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY-}
- AWS_SESSION_TOKEN=${AWS_SESSION_TOKEN-}
- AWS_CONTAINER_CREDENTIALS_FULL_URI=${AWS_CONTAINER_CREDENTIALS_FULL_URI-}
- AWS_CONTAINER_AUTHORIZATION_TOKEN=${AWS_CONTAINER_AUTHORIZATION_TOKEN-}

volumes:
redis-cache:
driver: local
19 changes: 16 additions & 3 deletions local-dev/local.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ ARG GOLANG_VERSION=1.22.4
RUN apt-get update \
&& apt-get install -y -qq \
tmux curl man less \
python3 git make
python3 ipython3 python-is-python3 \
git make \
redis-tools

# Install Go
RUN set -x && curl -L -o /var/tmp/go.tgz \
Expand Down Expand Up @@ -44,9 +46,20 @@ COPY --link --from=sources --chown=user:user /build/mod-files/ /build/src/

RUN cd /build/src/main && go mod download -x

# Download all modules for the payment commands. To make things simpler -execdir
# is used as it cd to the directory and properly fails if the command fails, but
# then the argument should be ignored and a shell insirection is used for that.
RUN find /build/src/tools/payments/cmd -type f -name go.mod \
-print -execdir /bin/sh -c 'go mod download -x' '{}' +

COPY --link --from=sources --chown=user:user /build/repo/ /build/src/

RUN cd /build/src/main \
&& CGO_ENABLED=0 GOOS=linux go build \
-o /build/bat-go main.go
&& go build -o /build/bat-go main.go

RUN rm -rf /build/src/tools/payments/dist \
&& mkdir -p /build/src/tools/payments/dist \
&& find /build/src/tools/payments/cmd -type f -name go.mod \
-print -execdir /bin/sh -c \
'go build -o "/build/src/tools/payments/dist/${PWD##*/}" main.go' '{}' +

Loading

0 comments on commit 76ce948

Please sign in to comment.