DevOps ã¨ã³ã¸ãã¢ã® æ ¹æ¬ å¾ ã§ãã
7æããã¨ã¯ãµã¦ã£ã¶ã¼ãº ã«ã¸ã§ã¤ã³ããCI / CD ãã¤ãã©ã¤ã³ã®æ¹åãèªåãã¹ãã®å¸æãªã©ãè¡ã£ã¦ãã¾ãã
ä»å㯠GitHub Actions ã® self-hosted runners ã AWS ECS ä¸ã«æ§ç¯ãéç¨ãã¦ã¿ãã®ã§ããã®è©¦è¡é¯èª¤ã«ã¤ãã¦ç´¹ä»ãããã¨æãã¾ãã
- GitHub Actions 㨠self-hosted runners
- self-hosted runners ã Docker ã§åãã
- self-hosted runners ã AWS ECS ã§åãã
- ã¢ããªã±ã¼ã·ã§ã³ã AWS ECS ã¸ãããã¤ãã Workflow ãä½ã
- ãããã«
GitHub Actions 㨠self-hosted runners
GitHub Actions 㯠GitHub ã¦ã¼ã¶ã¼ã§ããã°ç¾å¨å¤ãã®æ¹ããåç¥ã»ãæ´»ç¨ããã¦ãããã¨æãã¾ãã
GitHub Marketplace ã§å ¬éããã¦ãã Actions ã¨çµã¿åããããã¨ã«ãã£ã¦ãç°¡åã«æ§ã 㪠CI / CD ãã¤ãã©ã¤ã³ãæ§ç¯ãããã¨ãã§ãã¾ãã
ãã㪠GitHub Actions ã§ãããGitHubãæä¾ãã Runner ã使ã代ããã«èªåã§ç¨æãããã¨ãã§ãã¾ã(self-hosted runners)ã
GitHub ãæä¾ãã Runner 㧠GitHub Actionsãå©ç¨ããå ´åãç¡æå©ç¨æ + å¾é課éã®èª²éä½å¶ã«ãªãã¾ãã
ããããself-hosted runners 㧠GitHub Actions ãå©ç¨ããå ´åã«ã¯å¥éæéãããããã¨ã¯ããã¾ããã
Repository ã¾ã㯠Organization ã®è¨å®ããself-hosted runners ãã»ããã¢ãããããã¨ãã§ãã¾ã(Linux / MacOS / Windows æ¯ã«æé ã示ããã¾ã)ã
ã»ããã¢ãããå®äºããã¨ãRunner ã¨ãã¦è¿½å ããã¦ãããã¨ã確èªã§ãã¾ãã
Repository ã§è¨å®ãã Runner ã¯ãã® Repository ã§ããã㦠Organization ã§è¨å®ãã Runner ã¯ãã® Organization å ã®å ¨ã¦ã® Repository ã§å®è¡ãããã¨ãã§ãã¾ãã
æå¾ã« GitHub Actions ã®è¨å®ãã¡ã¤ã«ã«ããã¦ãself-hosted runners ã§å®è¡ãããã¨ãè¨è¿°ãã¾ãã
self-hosted runners ã¯ãã·ã³èªä½ã¯èªåãã¡ã§èª¿éã»ã¡ã³ããã³ã¹ãããªãã¨ãããªãã§ãããã¯ã¼ã¯ããã¼ã管çããé¨å(Jenkins ã§ãã master)ãèªåã§ç¨æããç¡æã§å©ç¨ã§ããç¹ã¯é åçã ã¨æãã¾ãã
self-hosted runners ã Docker ã§åãã
self-hosted runners èªä½ã¯ãªã¼ãã³ã½ã¼ã¹ã¨ãã¦å ¬éããã¦ãã¾ãããç¾å¨ Docker ã¤ã¡ã¼ã¸ã¯æä¾ããã¦ãã¾ããã
調ã¹ãã¨ãããDockerã»Kubernetes 㧠self-hosted runners åããããã«ãªã¼ãã³ã½ã¼ã¹ããã¸ã§ã¯ãã§æ§ã ãªè©¦è¡é¯èª¤ãè¡ããã¦ããã¿ããã§ãã
æ¬è¨äºã§ã¯ AWS ECS ãã¡ã¤ã³ã«ä¸è¨ã®æé ã§è§£èª¬ãã¾ãã
self-hosted runners ã Docker ã§åãã
self-hosted runners ã AWS ECS ã§åãã
ãã® self-hosted runners ãç¨ããã¢ããªã±ã¼ã·ã§ã³ã AWS ECS ã«ãããã¤ãããã¤ãã©ã¤ã³ãä½ã
ã¾ãä¸è¨ã® Docker ã¤ã¡ã¼ã¸ã使ããæå 㧠self-hosted runners ãç«ã¡ä¸ãã¦ã¿ã¾ãã
Organization ã«å¯¾ã㦠Runner ãç«ã¡ä¸ããããã«ã¯ä¸è¨ docker ã³ãã³ããå®è¡ãã¾ãã
GitHub Actions ã§ã¯ Docker ã®æä½(ãã«ããªã©)ãè¡ãããããã®ã³ã³ããå ã§ã Docker ã³ãã³ãã使ãããã¨ãå¿ è¦ã«ãªãã¾ãã
ãã®ããããã¹ããã·ã³ä¸ã® Docker daemon ãå
±æãããã¨ã§è§£æ±ºãã¦ãã¾ã(-v /var/run/docker.sock:/var/run/docker.sock
ã®é¨åãDocker outside of Docker)
Using Docker-in-Docker for your CI or testing environment? Think twice.
self-hosted runners ã AWS ECS ã§åãã
次ã«å ã»ã©ã® Docker ã¤ã¡ã¼ã¸ã使ã£ã¦ãAWS ECSã§åããã¦ã¿ã¾ãã
ä»å㯠AWS CDK(Typescript) ããã¼ã¹ã«3ã¤ã®ãã¤ã³ãã«çµã£ã¦è§£èª¬ãã¾ãã
1ã¤ç®ã« AWS ECS 㧠Docker outside of Docker(DooD) ãã©ãå®ç¾ãããã«ã¤ãã¦ã§ã(-v /var/run/docker.sock:/var/run/docker.sock
ã®é¨å)ã
AWS ECS ã 㨠Task å´ã« Volume ã追å ããContainer å´ã«ãã® Volume ããã¦ã³ããããã¨ã§è§£æ±ºãããã¨ãã§ãã¾ãã
AWS ECS ã§ã¯èµ·åã¿ã¤ãã¨ã㦠Fargate 㨠EC2 ãããã¾ãããç¾ç¶ Fargate ã§ä¸è¨ãè¡ããã¨ããµãã¼ãããã¦ããªãã£ããããä»åã¯EC2èµ·åã¿ã¤ããé¸æãã¾ããã
2ã¤ç®ã« ECS Task ã«ä¸ãã Role ã«ã¤ãã¦ã§ãã
ä»åã® GitHub Actions ä¸ã§ã®ãã¤ãã©ã¤ã³ã§ã¯ãDocker ãã«ã ã»ECRã¸ã®ã¤ã¡ã¼ã¸ã®ã¢ãããã¼ãã»ECSã¸ã®ãããã¤ã¾ã§è¡ããã¨ãã¦ãã¾ãã
ãã¡ãã GitHub å´ã« AWS ã¢ã¯ã»ã¹ãã¼ãä¿åããããã GitHub Action ã«æ¸¡ããã¨ã§ä¸è¨ãå®ç¾ãããã¨ãã§ãã¾ãã
ããããself-hosted runners ã®ã³ã³ããèªä½ã«ä¸è¨ã«å¿ è¦ãª Role ãä¸ãããã¨ã«ãã£ã¦ãGitHubå´ã« AWS ã¢ã¯ã»ã¹ãã¼ãä¿åããå¿ è¦èªä½ããªãããã¨ãã§ãã¾ãã
3ã¤ç®ã«ãã¹ãããã¤ã³ã¹ã¿ã³ã¹ã«ã¤ãã¦ã§ãã
self-hosted runners 㯠CI / CD ã¨ãã¦ä½¿ããããã¹ãããã¤ã³ã¹ã¿ã³ã¹ãæ´»ç¨ãã¦ã³ã¹ããæãããã¨ãã§ãã¾ãã
AWS CDK ã®å ´åãspotInstanceDraining
ããããã£ã true ã«ãããã¨ã§ã¹ãããã¤ã³ã¹ã¿ã³ã¹ãå©ç¨ãããã¨ãã§ãã¾ãã
ã¢ããªã±ã¼ã·ã§ã³ã AWS ECS ã¸ãããã¤ãã Workflow ãä½ã
ä»åã¯ãã® GitHub Actions 㨠self-hosted runners ãæ´»ç¨ãã¦ãã¢ããªã±ã¼ã·ã§ã³ã AWS ECS ã¸ãããã¤ãã Workflow ãä½ãããã¨æãã¾ãã
åã AWS ECS ãªã®ã§ããããããªã£ã¦ãã¾ãã¾ãããself-hosted runners ãåããã¯ã©ã¹ã¿ã¨ã¢ããªã±ã¼ã·ã§ã³ãåããã¯ã©ã¹ã¿ã¯å¥ã¨ããæ³å®ã§ãã
å ·ä½çã«ã¯ä¸è¨ã®ãããªæé ã«ãªãã¾ãã
Docker build ã㦠ECR ã«Pushãã â Task Definition ãã¡ã¤ã«ãç·¨éãã(Dockerã¤ã¡ã¼ã¸ã®é¨åãæ°ãããã) â Task Definition ãæ°ãã«ç»é²ããService ãæ´æ°ãããã¾ã§å¾ ã¤
AWSã§æä¾ããã¦ãã GitHub Actions ã® Step ã¨çµã¿åãããã¨ä¸è¨ã®ããã«ãªãã¾ãã
å
ã»ã©ãè¿°ã¹ã¾ããããæ¬æ¥ã¯ aws-actions/configure-aws-credentials
ã® Step ã§ä¸è¨ã®ããã« AWS ã¢ã¯ã»ã¹ãã¼ã GitHub ã«ä¿åã渡ãã¦ãããå¿
è¦ãããã¾ãã
ããããä»å㯠self-hosted runners ã«å¿ è¦ãªæ¨©éã渡ãã¦ããã¦ããã®ã§ãã®å¿ è¦ã¯ããã¾ããã
ãããã«
ä»åã¯GitHub Actions ã® self-hosted runners ã AWS ECS ä¸ã«æ§ç¯ãã¦ã¿ã¾ããããä¸è¨ã®ãããªç¶æ³ã§ã¡ãªãããããã¨èãã¦ãã¾ãã
GitHub Action ã使ã£ã¦ã¢ããªã±ã¼ã·ã§ã³ãAWSã¸ãããã¤ããéãGitHub å´ã«ä¸å¿ è¦ã« AWS ã¢ã¯ã»ã¹ãã¼ã渡ããããªã
ã¹ãããã¤ã³ã¹ã¿ã³ã¹ãæ´»ç¨ãããã¨ã«ãã£ã¦ãã³ã¹ãããã©ã¼ãã³ã¹ãã CI / CD ç°å¢ãéç¨ããã(ç¹ã«ç¡ææ ãå¤§å¹ ã«è¶ ãããã¨ãäºæ³ãããå ´å)
GitHub ãæä¾ãã Runner ããã¹ããã¯ã®é«ããã·ã³ã§ CI / CD ç°å¢ãéç¨ããã
ä»å¾ããã® GitHub Actions ããã¼ã¹ã«ããè¯ã CI / CD ãã¤ãã©ã¤ã³ãä½ãããè¯ãã¨èãã¦ãã¾ãã