我在将坞映像部署到AWS LightSail时遇到了问题。我在GitLab上使用私有容器,在构建之后,我的图像被推到了那里。我为ci/cd创建了第二阶段,用于将映像部署到lightsail。
image: docker:19.03.12
services:
- docker:19.03.12-dind
build:
stage: build
before_script:
- docker login registry.gitlab.com --username $UserName -p $CiCdToken
script:
- docker build -t registry.gitlab.com/nickname/testprojectname .
- docker push registry.gitlab.com/nickname/testprojectname
deploy:
stage: deploy
image: python:latest
script:
- pip install awscli
- pip install lightsailctl
- aws lightsail push-container-image --service-name testprojectname --label testprojectname --image registry.gitlab.com/nickname/testprojectname 不幸的是,python没有lightsailctl,awscli不支持lightsail。
lightsailaws ctl。最佳,Marcin Włoch
发布于 2021-01-02 12:16:55
这里有AWS CLI的2个版本,您需要的是版本2,它是唯一包含lightsail命令push-container-image的版本。您可以丢弃python:latest映像,因为这只用于修补AWSCLI v1。
请注意,为了上传对接图像,您将同时需要坞内对接者和AWSCLI (v2),这样您就可以在本地获得可以上传的图像。要做到这一点,最好的方法是使用docker映像并构建AWSCLI (v2)本地使用脚本。或者,您也可以尝试将docker添加到默认AWSCLIv2图像中,但是我不太喜欢这种方法,因为我更熟悉高山( docker映像的基本linux发行版),而且我喜欢它的轻量级和快速性。
以下是我的做法:
image: docker:19.03.12
services:
- docker:19.03.12-dind
build:
stage: build
before_script:
- docker login registry.gitlab.com -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}
script:
- docker build -t registry.gitlab.com/nickname/testprojectname:${CI_PIPELINE_ID} .
- docker push registry.gitlab.com/nickname/testprojectname:${CI_PIPELINE_ID}
deploy:
stage: deploy
image: docker # NOTE: we need docker cli to make this work!
variables:
AWS_ACCESS_KEY_ID: MYSUPERSECRETACCESSKEYID
AWS_SECRET_ACCESS_KEY: MYSUPERSECRETACCESSKEYSECRET
AWS_DEFAULT_REGION: eu-west-1
before_script:
# 1. Install AWSCLIv2 (https://stackoverflow.com/questions/60298619/awscli-version-2-on-alpine-linux#answer-61268529)
- ./alpine.awscliv2.install.sh
- aws --version
# 2. Install LightsailCTL Plugin (https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-install-software)
- apk --no-cache add curl jq
- curl https://s3.us-west-2.amazonaws.com/lightsailctl/latest/linux-amd64/lightsailctl -o /usr/local/bin/lightsailctl
- chmod +x /usr/local/bin/lightsailctl
script:
# 3. Download the docker image for this pipeline
- docker info
- docker login registry.gitlab.com -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}
- docker pull registry.gitlab.com/nickname/testprojectname:${CI_PIPELINE_ID}
# 4. Upload the docker image for this pipeline
- aws lightsail push-container-image
--service-name testprojectname
--label pipeline-${CI_PIPELINE_ID}
--image registry.gitlab.com/nickname/testprojectname:${CI_PIPELINE_ID}
# 5. Get the uploaded image (its different every time)
- PIPELINE_IMAGE_TAG=$(aws lightsail get-container-images --service testprojectname | jq -r .containerImages[0].image)
# 6. Create a deployment with the uploaded docker image
- aws lightsail create-container-service-deployment
--service-name testprojectname
--containers "{\"testprojectname\":{\"image\":\"$PIPELINE_IMAGE_TAG\",\"ports\":{\"8000\":\"HTTP\"}}}"
--public-endpoint "{\"containerName\":\"testprojectname\",\"containerPort\":8000,\"healthCheck\":{\"path\":\"/\"}}"发布于 2020-12-25 18:25:47
"aws lightsail推-容器-图像“可能需要码头。
我创建了一个包含awscli、lightsailctl和docker的映像。
- image: python:latest
+ image: ytoune/aws-lightsail-cli
script:
- - pip install awscli
- - pip install lightsailctlhttps://stackoverflow.com/questions/65159967
复制相似问题