git status
git add -A
git commit -m "app enviada para o repo"
git push
cloudmart-cicd-pipeline
cloudmart-application
como a fonte.cloudmartBuild
).cloudmart-application
).buildspec.yml
:version: 0.2
phases:
install:
runtime-versions:
docker: 20
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- REPOSITORY_URI=$ECR_REPO
**- aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/l4c0j8h9**
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build -t $REPOSITORY_URI:latest .
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$CODEBUILD_RESOLVED_SOURCE_VERSION
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$CODEBUILD_RESOLVED_SOURCE_VERSION
- export imageTag=$CODEBUILD_RESOLVED_SOURCE_VERSION
- printf '[{\\"name\\":\\"cloudmart-app\\",\\"imageUri\\":\\"%s\\"}]' $REPOSITORY_URI:$imageTag > imagedefinitions.json
- cat imagedefinitions.json
- ls -l
env:
exported-variables: ["imageTag"]
artifacts:
files:
- imagedefinitions.json
- cloudmart-frontend.yaml
Criar um Projeto de Implantação:
cloudmartDeployToProduction
).eks-user
no Cloud Build, para que ele possa autenticar-se no cluster Kubernetes.Observe: em um ambiente de produção do mundo real, é recomendável usar uma função do IAM para essa finalidade. Neste exercício prático, estamos usando diretamente as credenciais do usuário eks-user
para facilitar o processo, já que nosso foco é na CI/CD e não na autenticação do usuário neste momento. A configuração desse processo no EKS é mais extensa. Consulte a seção de Referência e consulte "Habilitando o acesso de princípio do IAM ao seu cluster"
buildspec.yml
:version: 0.2
phases:
install:
runtime-versions:
docker: 20
commands:
- curl -o kubectl <https://amazon-eks.s3.us-west-2.amazonaws.com/1.18.9/2020-11-02/bin/linux/amd64/kubectl>
- chmod +x ./kubectl
- mv ./kubectl /usr/local/bin
- kubectl version --short --client
post_build:
commands:
- aws eks update-kubeconfig --region us-east-1 --name cloudmart
- kubectl get nodes
- ls
- IMAGE_URI=$(jq -r '.[0].imageUri' imagedefinitions.json)
- echo $IMAGE_URI
- sed -i "s|CONTAINER_IMAGE|$IMAGE_URI|g" cloudmart-frontend.yaml
- kubectl apply -f cloudmart-frontend.yaml
cloudmart-frontend.yaml
por CONTAINER_IMAGE.git add -A
git commit -m "replaced image uri with CONTAINER_IMAGE"
git push
Faça uma Alteração no GitHub:
cloudmart-application
.src/components/MainPage/index.jsx
linha 93git add -A
git commit -m "alternado para Main Products"
git push
Observe a Execução da Pipeline: