ã¯ããã«
Actix web 㧠Web ã¢ããªã±ãŒã·ã§ã³ãäœã£ãã®ã§ãããæè¡å匷ãå ŒããŠããã®ã§ããããã€å ãä»ãŸã§è©Šããããšããªããã®ãè©ŠãããšããŠããŸãããããã§ãæ¥é æ¥åã§ã AWS ãå©çšããŠãããšããããšããããå»å¹Žæ«ã«çºè¡šããã AWS Lightsail Containers ããããã€å ã«æ¡çšããŸããã
AWS Lightsail Containers ãžã®ãããã€èªäœã¯éåžžã«ç°¡åã§ããããŸãããããã€ã«ããã Rust ã® Docker ã€ã¡ãŒãžäœæã®ããæ¹ãåŠã¹ãŸãããä»åã¯ãã®ãããã®æé ããŸãšãã圢ã§èšäºãšããŠæžãæ®ããŠããããšã«ããŸããã
Actix web ã® Docker ã€ã¡ãŒãžãäœæãã
éçºããã¢ããªã±ãŒã·ã§ã³ã§ã¯ React ã§ããã³ããšã³ãéçºãããŠããŠããã«ããããã®ã Actix web ã® public ãã©ã«ãã«é
眮ãã圢ã§å
¬éããŠããŸãããã®ãããäžèšã® Dockerfile ã§ã¯ãã«ãã¹ããŒãžãã«ããå©çšããŠãããŸãããæ¬è³ªçã«ã¯ FROM rust:1.49
以éã®èšè¿°ã Actix web ã«é¢ãããã®ãšãªããŸãã
# React ãã«ãçšã®ã€ã¡ãŒãž
FROM node:14.15.4-alpine3.10 as client_builder
ARG REACT_APP_API_URL
ARG REACT_APP_GYAZO_AUTH_URL
ARG REACT_APP_GA_UNIVERSAL_ID
WORKDIR /client
COPY ./client/package*.json .
RUN yarn install
ADD ./client .
RUN yarn build
# Actix web ãã«ãçšã®ã€ã¡ãŒãž
FROM rust:1.49
# Actix web ã«ã¢ã¯ã»ã¹ããããã®ããŒããå
¬éãã
EXPOSE 8080
# Actix web ãããžã§ã¯ãã®ãã©ã«ããã€ã¡ãŒãžã«è¿œå ãã
WORKDIR /server
ADD ./server .
# ãããžã§ã¯ããã©ã«ãå
㧠`cargo install` ããŠãã«ããçæãã
RUN cargo install --path .
# äžèŠã«ãªã£ããã¡ã€ã«çŸ€ãåé€ãã
RUN ls | grep -v -E 'templates' | xargs rm -r
# React ãã«ãçšã®ã€ã¡ãŒãžã§ãã«ãããå
容ã Actix web ãã«ãçšã€ã¡ãŒãžã«è¿œå ãã
COPY --from=client_builder /client/build ./build
RUN mkdir tmp
# `cargo install` ã³ãã³ãã§çæãããã«ããå®è¡ã㊠Actix web ãèµ·åãã
# äžèšã®ã³ãã³ãå称㯠Cargo.toml å
ã® [package.name] ã«æºãã
CMD ["bloggimg-server"]
ãŸããDocker ãã«ãæã®ãªãã·ã§ã³ç®¡çã楜ã«ãããããDocker Compose ãå©çšããŸãããåäžã® Docker ã€ã¡ãŒãžããã«ãããéã«ãå©çšããŠããããšã§ãåŸã ã³ã³ãããè¿œå ããŠé£æºãããããšãã«ãå³åº§ã«å¯Ÿå¿ã§ãããã§ãªã¹ã¹ã¡ã§ãã
# docker-compose.yml
# context ã« Actix web ãããžã§ã¯ãã®ãã¹ãæå®ãã
# args ã« Docker ãã«ãæã«å©çšããã ARGS ã®å€ãç°å¢å€æ°ã§èšå®ãã
# image ã« Docker ã® <ã€ã¡ãŒãžå:ã¿ã°å> ãæå®ãã (ä»å㯠Docker Hub ã«ãããã€ããæ³å®)
# env_file ã«éçº/åäœæ€èšŒæã«å©çšããã dotenv ãã¡ã€ã«ãæå®ãã
# ports ã«ããŒããããã³ã°ã®èšå®ãæžã
version: "3.8"
services:
app:
build:
context: ./
args:
- REACT_APP_API_URL=${REACT_APP_API_URL}
- REACT_APP_GYAZO_AUTH_URL=${REACT_APP_GYAZO_AUTH_URL}
- REACT_APP_GA_UNIVERSAL_ID=${REACT_APP_GA_UNIVERSAL_ID}
image: nikaera/bloggimg:v1.0.0
env_file:
- ./server/.env
ports:
- 8080:8080
äžèšãèªåã® Actix web ãããžã§ã¯ãã«å¿ããŠæ¹å€ã docker-compose up
ããŠåäœæ€èšŒããŸããåäœæ€èšŒãã§ã次第ãdocker-compose build
ãå®è¡ã㊠Docker ã€ã¡ãŒãžããã«ãããŸãããã«ãã«æåããã次㯠Docker Hub ã«ã€ã¡ãŒãžã push ããŸãã
Docker Hub ã«ãã«ãããã€ã¡ãŒãžã push ãã
ä»å㯠AWS Lightsail Containers ã§äœ¿çšããã€ã¡ãŒãžã®ç®¡çã« Docker Hub ãå©çšããŸããDocker Hub ãž push ããåã« docker login --username=<Docker Hub ã®ãŠãŒã¶å>
ã³ãã³ã㧠Docker Hub ãžã®ãã°ã€ã³ãæžãŸããŠãããŸãã
ãã®åŸ docker-compose push
ã³ãã³ã㧠Docker ã€ã¡ãŒãžã Docker Hub ã« push ããŸãã
Docker Hub ã®ããŒãžãããæ£åžžã« Docker ã€ã¡ãŒãžã push ã§ããŠãããã確èªãã
Docker ã€ã¡ãŒãžã® push ãæåããŠããããšã確èªã§ããããæ®ã㯠AWS Console äžã§ã®äœæ¥ã«ãªããŸãã
AWS Console ãã Lightsail Containers Service ãäœæãã
AWS Console ã«ãã°ã€ã³åŸãLightsail ãµãŒãã¹ ãéžæã㊠Lightsail ãµãŒãã¹ã®ãããããŒãžãžé·ç§»ããŸããé·ç§»ããã Containers ã¿ããéžæããCreate container services
ãã¿ã³ãã Container Service ãäœæããŸãã
AWS Console ãžãã°ã€ã³åŸ Lightsail ã®ããŒãžã«é·ç§»ããŠãContainers ã¿ããéžæãã
Containers ã¿ããéžæãããšåºãŠãããCreate container services
ãã¿ã³ãã¯ãªãã¯ãã
Create container services
ãã¿ã³ãã¯ãªãã¯ããé·ç§»å
ã®ç»é¢ã§ããªãŒãžã§ã³ããã£ãã·ã㣠(Micro ã§ããã° 3 ã¶æéã®ã¿ç¡æã§å©çšå¯èœ) çãéžæããŠãå称ãå
¥åããŸããä»åã¯æåã«ãããã€ã®ããã®æºåããã§ã«æžãŸããŠããã®ã§ãContainer Service ãäœæããã€ãã§ã«ãããã€èšå®ãè¡ããŸãã
ãããã€èšå®ã¯ Set up your first deployment
ã®é
ç®ããè¡ãããšãå¯èœã§ãã
Set up deployment
ã®éšåãã¯ãªãã¯ããŠããããã€ã®èšå®é
ç®ã衚瀺ãã
Docker Hub ã€ã¡ãŒãžãå©çšããŠãããã€ããéã«å¿ èŠãªèšå®é ç®ãå ¥åãã
ã³ã³ããã®ãã«ã¹ãã§ãã¯ã®ããã®æ å ±ãå ¥åãã
ãã¹ãŠã®æ
å ±å
¥åãå®äºããã Create container services
ãã¿ã³ãã¯ãªãã¯ãã
é·ç§»åŸã®ç»é¢äžéšã® Deployment versions
ãããããã€ç¶æ³ã®ç¢ºèªãè¡ãã
æ£åžžã«ãããã€ã§ããŠããã° Deployment versions
ã®é
ç®ã Active ã«ãªã
ãããã€ãå®äºããã Public domain
ãçºè¡ãããŠããã¯ããªã®ã§ãæ£åžžã«ã¢ã¯ã»ã¹ã㊠Web ã¢ããªã±ãŒã·ã§ã³ãå©çšã§ãããã確èªããŸããPublic domain
ã¯è©²åœãã Container Service ã®ãããããŒãžãã確èªã§ããŸãã
AWS Lightsail Containers ã®ãããããŒãžã«ãã Public domain
ããåäœæ€èšŒãã
äžéãã®åäœæ€èšŒãè¡ããæ£åžžã«ãããã€ã§ããŠãããã確èªãã
ããã§äœæ¥ã¯å®äºã§ããæ°ãã Docker ã€ã¡ãŒãžã§ãããã€ãçŽãããå Žåã¯ãDeployments
ã¿ãã® Modify your deployment
ãªã³ã¯ãã¯ãªãã¯ããã°å¯èœã§ãã
(ããŸã) ç¬èªãã¡ã€ã³ã§ Container Service ãžã¢ã¯ã»ã¹å¯èœã«ãã
AWS Lightsail Containers ã§ã¯ç¬èªãã¡ã€ã³ã®çŽä»ãåã³ãHTTPS åãç°¡åã«èšå®ã§ããŸããCustom domains
ã¿ããéžæããåŸãç»é¢äžéšã«ãã Create certificate
ãªã³ã¯ãã¯ãªãã¯ããããšã§èšå®ç»é¢ã衚瀺ããŸãã
Custom domain
ã¿ããã¯ãªãã¯ããŠãããCreate certificate
ãªã³ã¯ãã¯ãªãã¯ãã
åçš®èšå®é
ç®ã®å
¥åãå®äºããã Create
ãã¿ã³ãã¯ãªãã¯ãã
ãã¡ã€ã³æ€èšŒã®ããã«ãCNAME ã¬ã³ãŒãã®èšå®ãæ±ããããã®ã§åèªã§èšå®äœæ¥ãè¡ã
æ£åžžã« CNAME ã¬ã³ãŒããèšå®ããåŸããã°ããçµã€ãš Status ã Valid ã«ãªã
äžèšãŸã§ç¢ºèªããããCreate certificate
ã§èšå®ãããã¡ã€ã³ã® CNAME ã¬ã³ãŒãã« Public domain
ã®å€ãèšå®ããŠãããŸããèšå®å
容ãåæ ãã次第ãç¬èªãã¡ã€ã³ãžã¢ã¯ã»ã¹ããããšã§ HTTPS çµç±ã§ Container Service ãžã¢ã¯ã»ã¹ã§ããããã«ãªããŸãã
Custom domains
㧠Container Service ã§èµ·åããŠãããµãŒãã¹ã«ã¢ã¯ã»ã¹ã§ããããšã確èªãã
ãããã«
AWS Lightsail Containers ãå©çšã㊠Actix web ãããžã§ã¯ãããããã€ããæé ã«ã€ããŠç°¡åã«ãŸãšããŠã¿ãŸããã䟿å©ã§ã¯ãããã®ã®ãå人éçºã§å©çšããåã«ã¯äŸ¡æ Œé¢åã³æ§èœé¢ã§ Lightsail Instance ã®ã»ããè¯ããªãšçŸæç¹ã§ã¯æããŠããŸããŸããã
ããããæ¥æ¬ãªãŒãžã§ã³ãçšæãããŠãããããŒããã©ã³ãµãŒãåããŠããããç°¡åã«ã¹ã±ãŒã«ããããããã€å®é¡ã§å©çšå¯èœãªãµãŒãã¹ã§ãããšããã¡ãªããã掻ãããå Žé¢ãããã°æå¹æŽ»çšã§ãããã ãªãšæããŸããã