Telegram Web Link
como desde un gitlabci construir imagen .net crear un docker con ella docker y subir a ecr con un tag abrebiado y despues actualizar el ecs


stages:
- compile
- build
- deploy



compile:
stage: compile
image: mcr.microsoft.com/dotnet/sdk:latest
script:
- dotnet build -o build/
artifacts:
paths:
- build/
Hacemos el build 👇

build_image:
stage: build
image:
name: armandofcom/deploy:docker-awscli
entrypoint: [""]
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
environment: develop
before_script:
- DOCKER_HOST='/var/run/docker.sock'; if [ ! -S "$DOCKER_HOST" ]; then DOCKER_HOST='tcp://docker:2375'; export DOCKER_HOST=$DOCKER_HOST;fi; echo $DOCKER_HOST
- echo "Logging in to Amazon ECR..."
- aws ecr get-login-password --region eu-south-2 | docker login --username AWS --password-stdin *****.dkr.ecr.eu-south-2.amazonaws.com
script:
- echo "Building Docker image..."
- docker build -t $ECR_REPOSITORY_URI:${CI_COMMIT_SHORT_SHA} .
- echo "Pushing Docker image to ECR..."
- docker push $ECR_REPOSITORY_URI:${CI_COMMIT_SHORT_SHA}
only:
- develop
Please open Telegram to view this post
VIEW IN TELEGRAM
actualizar el tag


stage: deploy
image: armandofcom/deploy:docker-awscli
environment: develop
before_script:
- apk update
- apk add jq
script:
- TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition $SERVICE_NAME --region eu-south-2)
- NEW_CONTAINER_DEFINTIION=$(echo $TASK_DEFINITION | jq --arg IMAGE "$ECR_REPOSITORY_URI:${CI_COMMIT_SHORT_SHA}" '.taskDefinition | .containerDefinitions[0].image = $IMAGE | del(.taskDefinitionArn) | del(.revision) | del(.status) | del(.requiresAttributes) | del(.compatibilities) | del(.registeredAt) | del(.registeredBy)')
- echo "Registering new container definition..."
- NEW_TASK_INFO=$(aws ecs register-task-definition --region eu-south-2 --family $SERVICE_NAME --cli-input-json "${NEW_CONTAINER_DEFINTIION}")
- NEW_REVISION=$(echo $NEW_TASK_INFO | jq '.taskDefinition.revision')
- echo "Updating the service..."
- aws ecs update-service --region eu-south-2 --cluster $CLUSTER_NAME --service $SERVICE_NAME --task-definition $SERVICE_NAME:${NEW_REVISION}
only:
- develop
dependencies:
- build_image
Están chulas las oficinas de Google en Madrid
2024/11/19 22:23:17
Back to Top
HTML Embed Code: