Kev ntsuam xyuas yog ib feem tseem ceeb ntawm txoj kev txhim kho. Thiab qee zaum cov neeg tsim khoom yuav tsum tau ua qhov kev sim hauv zos, ua ntej hloov pauv.
Yog tias daim ntawv thov siv Amazon Web Services, nab hab sej tsev qiv ntawv moto zoo meej rau qhov no.
Ib daim ntawv teev tag nrho ntawm kev pab them nqi kho mob tuaj yeem pom
Muaj ib tug turnip ntawm Github Hugo Picado -
Zoo, qhov ntawd yog qhov yooj yim txaus los kho.
Txij li thaum pib koj yuav tsum tau qhia txog hom kev pabcuam (kwv yees sib txawv MOTO_SERVICE), peb tsuas yog yuav tsum piav qhia txog kev tsim cov peev txheej.
Cia peb hloov nws me ntsis pib.sh:
Hloov chaw
moto_server $MOTO_SERVICE -H $MOTO_HOST -p $MOTO_PORT
Ntxig:
if [ -f /opt/init/bootstrap.py ]; then
moto_server $MOTO_SERVICE -H $MOTO_HOST -p $MOTO_PORT & (sleep 5 && echo "Executing bootstrap script." && python /opt/init/bootstrap.py)
else
moto_server $MOTO_SERVICE -H $MOTO_HOST -p $MOTO_PORT
fi
wait
Cov ntaub ntawv kawg yog:
pib.sh
#!/bin/sh
# validate required input
if [ -z "$MOTO_SERVICE" ]; then
echo "Please define AWS service to run with Moto Server (e.g. s3, ec2, etc)"
exit 1
fi
# setting defaults for optional input
if [ -z "$MOTO_HOST" ]; then
MOTO_HOST="0.0.0.0"
fi
if [ -z "$MOTO_PORT" ]; then
MOTO_PORT="5000"
fi
echo "Starting service $MOTO_SERVICE at $MOTO_HOST:$MOTO_PORT"
if [ -f /opt/init/bootstrap.py ]; then
moto_server $MOTO_SERVICE -H $MOTO_HOST -p $MOTO_PORT & (sleep 5 && echo "Executing bootstrap script." && python /opt/init/bootstrap.py)
else
moto_server $MOTO_SERVICE -H $MOTO_HOST -p $MOTO_PORT
fi
# Prevent container from exiting when bootstrap.py finishing
wait
Peb tsim cov duab tshiab thiab thawb nws mus rau hauv peb lub npe.
Tom ntej no, cia peb sau ib tsab ntawv sau npe pib, piv txwv SWB Domain, siv lub tsev qiv ntawv ua haujlwm nrog AWS - boto3:
bootstrap_swf.py
import boto3
from botocore.exceptions import ClientError
import os
os.environ["AWS_ACCESS_KEY_ID"] = "fake"
os.environ["AWS_SECRET_ACCESS_KEY"] = "fake"
client = boto3.client('swf', region_name='us-west-2', endpoint_url='http://localhost:5000')
try:
client.register_domain(
name='test-swf-mock-domain',
description="Test SWF domain",
workflowExecutionRetentionPeriodInDays="10"
)
except ClientError as e:
print "Domain already exists: ", e.response.get("Error", {}).get("Code")
response = client.list_domains(
registrationStatus='REGISTERED',
maximumPageSize=123,
reverseOrder=True|False
)
print 'Ready'
Lub logic yog qhov no:
- Thaum pib, peb mount peb tsab ntawv nyob rau hauv /opt/init/bootstrap.py.
- Yog hais tias cov ntaub ntawv yog mounted, nws yuav raug tua.
- Yog tias tsis muaj cov ntaub ntawv, tus liab qab moto-server tsuas yog pib.
Thiab, koj tuaj yeem thuam tag nrho cov peev txheej los ntawm kev tso ib lub thawv:
docker run --name swf -d
-e MOTO_SERVICE=swf
-e MOTO_HOST=0.0.0.0
-e MOTO_PORT=5000
-p 5001:5000
-v /tmp/bootstrap_swf.py:/opt/init/bootstrap.py
-i awesome-repo.com/moto-server:latest
Wb sim nws interactively:
ΠΠ±ΠΎΡΠ°Π΅Ρ!
Yog li peb tuaj yeem ua docker-compose.yml, uas yuav txuag lub sijhawm sim hloov pauv:
docker-compose.yml
version: '3'
services:
s3:
image: picadoh/motocker
environment:
- MOTO_SERVICE=s3
- MOTO_HOST=10.0.1.2
ports:
- "5002:5000"
networks:
motonet:
ipv4_address: 10.0.1.2
volumes:
- /tmp/bootstrap_s3.py:/opt/init/bootstrap.py
swf:
image: picadoh/motocker
environment:
- MOTO_SERVICE=swf
- MOTO_HOST=10.0.1.3
ports:
- "5001:5000"
networks:
motonet:
ipv4_address: 10.0.1.3
volumes:
- /tmp/bootstrap_swf.py:/opt/init/bootstrap.py
ec2:
image: picadoh/motocker
environment:
- MOTO_SERVICE=ec2
- MOTO_HOST=10.0.1.4
ports:
- "5003:5000"
networks:
motonet:
ipv4_address: 10.0.1.4
volumes:
- /tmp/bootstrap_ec2.py:/opt/init/bootstrap.py
networks:
motonet:
driver: bridge
ipam:
config:
- subnet: 10.0.0.0/16
Qhov tseeb, txoj hauv kev no tuaj yeem siv tsis yog ntawm tus tsim tawm lub laptop xwb. Kev sim ua ntej nrog kev thuam tom qab sib dhos yuav pab tshem tawm cov teeb meem tshwm sim thaum khiav ntawm dev * ib puag ncig.
Links:
Motocker rov -
Moto repo -
Boto3 Docs -
Tau qhov twg los: www.hab.com