Skip to content

install and start moto #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ jobs:
file: ${{ matrix.context }}/Dockerfile
context: ${{ matrix.context }}
build-args: ${{ matrix.args }}
platforms: linux/amd64,linux/arm64
# platforms: linux/amd64,linux/arm64
platforms: linux/amd64
pull: true
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
16 changes: 15 additions & 1 deletion devcontainer/aws/localstack/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ ARG LOCALSTACK_MINOR=1
ENV LOCALSTACK_MINOR=${LOCALSTACK_MINOR}
ARG LOCALSTACK_PATCH=0
ENV LOCALSTACK_PATCH=${LOCALSTACK_PATCH}
ARG MOTO_MAJOR=5
ENV MOTO_MAJOR=${MOTO_MAJOR}
ARG MOTO_MINOR=0
ENV MOTO_MINOR=${MOTO_MINOR}
ARG MOTO_PATCH=9
ENV MOTO_PATCH=${MOTO_PATCH}
ARG NPM_MAJOR=latest
ENV NPM_MAJOR=${NPM_MAJOR}

Expand Down Expand Up @@ -123,6 +129,7 @@ RUN pipx install awscli-local

# Localstack
RUN pipx install --include-deps localstack[full]==${LOCALSTACK_MAJOR}.${LOCALSTACK_MINOR}.${LOCALSTACK_PATCH}
RUN pipx install moto[server]==${MOTO_MAJOR}.${MOTO_MINOR}.${MOTO_PATCH}

COPY root /root
COPY bin /bin
Expand All @@ -141,6 +148,9 @@ ENV LOCALSTACK_PORT="4566"
ENV GATEWAY_LISTEN="0.0.0.0:${LOCALSTACK_PORT}"
ENV OVERRIDE_IN_DOCKER=1

# Moto Env
ENV MOTO_PORT="5000"

# AWS Env
ENV AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE=1

Expand All @@ -158,7 +168,11 @@ RUN ARCH=$(uname -m) && \

# Runtime Env
ENV STAGE="local"
ENV LOCALSTACK="true"
ENV LOCALSTACK="false"
ENV MOTO="true"

# Cloud Switch-a-roo
ENV CLOUD_PORT="5000"
# ENV POD_PATH="/var/lib/localstack/pod"

# Root FS
Expand Down
11 changes: 11 additions & 0 deletions devcontainer/aws/localstack/etc/supervisor/conf.d/moto.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[program:moto]
user=root
group=root
command=/root/.local/bin/moto_server -H 0.0.0.0
autostart=true
autorestart=true
stdout_logfile=/var/log/moto.log
redirect_stderr=true
stopsignal=INT
startretries=60
stopwaitsecs=30
44 changes: 38 additions & 6 deletions devcontainer/aws/localstack/usr/local/bin/eventlistener.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def set_aws_config(port):
os.system(f"aws configure set default.endpoint_url \"\"")
return

endpoint_url = f"http://localhost.localstack.cloud:{port}"
endpoint_url = f"http://localhost:{port}"

codespace_name = get_secret("CODESPACE_NAME")
domain = get_secret("GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN")
Expand All @@ -185,6 +185,10 @@ def load_localstack_pod():
write_stderr("NOT IMPLEMENTED: Restoring localstack state")


def load_moto_state():
write_stderr("NOT IMPLEMENTED: Restoring moto state")


def save_localstack_pod():
pod_path = os.getenv("POD_PATH")

Expand All @@ -194,6 +198,10 @@ def save_localstack_pod():
write_stderr("NOT IMPLEMENTED: Saving localstack state")


def save_moto_state():
write_stderr("NOT IMPLEMENTED: Saving moto state")


def ensure_public_ports(exclude=[]):
for port in public_ports:
if port in exclude:
Expand All @@ -209,9 +217,14 @@ def ensure_public_ports(exclude=[]):


def main():
cloud_port = os.getenv("CLOUD_PORT", None)

localstack_port = os.getenv("LOCALSTACK_PORT", None)
localstack_running = False

moto_port = os.getenv("MOTO_PORT", None)
moto_running = False

while True:
headers, body = listener.wait(sys.stdin, sys.stdout)
body = dict([pair.split(":") for pair in body.split(" ")])
Expand All @@ -222,31 +235,50 @@ def main():
write_stderr(f"Received {eventname} from {processname}.")

if eventname == "TICK_5":
ensure_public_ports(exclude=[localstack_port])
ensure_public_ports(exclude=[localstack_port, moto_port])

# HACK: Startup ordering:
# - it appears that the port flips back to private sometime in the startup process
if localstack_running:
# HACK: Startup ordering:
# - it appears that the port flips back to private sometime in the startup process
open_port(localstack_port)

if moto_running:
open_port(moto_port)

if eventname == "PROCESS_STATE_STARTING":
if processname == "localstack":
if processname == "localstack" and cloud_port == localstack_port:
set_aws_config(localstack_port)

if processname == "moto" and cloud_port == moto_port:
set_aws_config(moto_port)

if eventname == "PROCESS_STATE_RUNNING":
if processname == "localstack":
wait_for_port(localstack_port)
open_port(localstack_port)
load_localstack_pod()
localstack_running = True

if processname == "moto":
wait_for_port(moto_port)
open_port(moto_port)
load_moto_state()
moto_running = True

if eventname == "PROCESS_STATE_STOPPING":
if processname == "localstack":
localstack_running = False
save_localstack_pod()

if processname == "moto":
moto_running = False
save_moto_state()

if eventname == "PROCESS_STATE_STOPPED":
if processname == "localstack":
if processname == "localstack" and cloud_port == localstack_port:
set_aws_config(None)

if processname == "moto" and cloud_port == moto_port:
set_aws_config(None)

# acknowledge the event
Expand Down
Loading