diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml index 7b5c4bd..059fb2f 100644 --- a/.github/workflows/build-push.yml +++ b/.github/workflows/build-push.yml @@ -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 }} diff --git a/devcontainer/aws/localstack/Dockerfile b/devcontainer/aws/localstack/Dockerfile index 509d2c3..6d1706d 100644 --- a/devcontainer/aws/localstack/Dockerfile +++ b/devcontainer/aws/localstack/Dockerfile @@ -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} @@ -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 @@ -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 @@ -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 diff --git a/devcontainer/aws/localstack/etc/supervisor/conf.d/moto.conf b/devcontainer/aws/localstack/etc/supervisor/conf.d/moto.conf new file mode 100644 index 0000000..99dd7ad --- /dev/null +++ b/devcontainer/aws/localstack/etc/supervisor/conf.d/moto.conf @@ -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 diff --git a/devcontainer/aws/localstack/usr/local/bin/eventlistener.py b/devcontainer/aws/localstack/usr/local/bin/eventlistener.py index ea05c41..0c605e7 100755 --- a/devcontainer/aws/localstack/usr/local/bin/eventlistener.py +++ b/devcontainer/aws/localstack/usr/local/bin/eventlistener.py @@ -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") @@ -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") @@ -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: @@ -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(" ")]) @@ -222,17 +235,23 @@ 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) @@ -240,13 +259,26 @@ def main(): 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