19 Eylül 2022 Pazartesi

Amazon Web Service (AWS) CodeDeploy ve CodePipeline

Giriş
Açıklaması şöyle
AWS CodeDeploy and AWS CodePipeline are two AWS deployment services. AWS CodeDeploy automates the deployment of code to an EC2 instance. After we commit any changes to a specific branch, CodePipeline builds, tests, and deploys our application.
Adımlar şöyle
The basic steps are below:
1. Prepare Spring boot application and push it to GitHub
2. Setup IAM role. We will need two IAM role. Role for EC2 and Code deploy. EC2 role will require S3 and code deploy permission.
3. Launch EC2 instance
4. Create application in code deploy
5. Setup code pipeline
IAM ve geri kalan her tüm ekranları gösteren bir örnek burada

buildspec.yml
Projeyi yapılandırır
Örnek
Şöyle yaparız. Burada JDK 11 Correto ve maven kullanılıyor
version: 0.2

phases:
  install:
    runtime-versions:
      java: corretto11
  build:
    commands:
      - mvn clean install
  post_build:
    commands:
      - echo Build completed
artifacts:
  files:
    - target/*.jar
    - scripts/*.sh
    - appspec.yml
  discard-paths: yes
appspec.yml
Örnek
Şöyle yaparız
version: 0.0
os: linux

files:
  - source: /
    destination: /home/ec2-user/server

permissions:
  - object: /
    pattern: "**"
    owner: ec2-user
    group: ec2-user

hooks:
  BeforeInstall:
    - location: server_clear.sh
      timeout: 300
      runas: ec2-user
  AfterInstall:
    - location: fix_privileges.sh
      timeout: 300
      runas: ec2-user
  ApplicationStart:
    - location: server_start.sh
      timeout: 20
      runas: ec2-user
  ApplicationStop:
    - location: server_stop.sh
      timeout: 20
      runas: ec2-user
Açıklaması şöyle
This will copy files to /home/ec2-user/server folder that I mentioned in the artifacts part of the buildspec.yml. Hooks allow us to run different scripts at different stages of the deployment. In the start script, I added the command to run the jar and open port 80 so we can access the API.





Hiç yorum yok:

Yorum Gönder