gpt4 book ai didi

docker - Circleci 2.0 基于 Dockerfile 构建

转载 作者:行者123 更新时间:2023-12-02 18:53:45 26 4
gpt4 key购买 nike

我有一个 Node.JS 应用程序,我想使用 CircleCI 和 Amazon ECR 构建和测试它。该文档不清楚如何从存储库中的 Dockerfile 构建镜像。我看过这里:https://circleci.com/docs/2.0/building-docker-images/在这里 https://circleci.com/blog/multi-stage-docker-builds/但不清楚我在执行者下放置了什么。这是我到目前为止所得到的:

version: 2
jobs:
build:
docker:
steps:
- checkout
- setup_remote_docker:
version: 17.05.0-ce
# build the image
- run: docker build -t $ECR_REPO:0.1 .

CircleCI 失败并出现以下错误:

* The job has no executor type specified. The job should have one of the following keys specified: "machine", "docker", "macos"

基础镜像取自 Dockerfile。我正在使用 CircleCI 内置的 AWS 集成,因此我认为不需要添加 aws_auth。我需要在执行器下放置什么才能使其运行?

最佳答案

使用 Docker-in-Docker 配置构建它:

version: 2
jobs:
build:
working_directory: /app
docker:
- image: docker:17.05.0-ce-git
steps:
- checkout
- setup_remote_docker
- run:
name: Install dependencies
command: |
apk add --no-cache \
py-pip=9.0.0-r1 gcc \
libffi-dev python-dev \
linux-headers \
musl-dev \
libressl-dev \
make
pip install \
docker-compose==1.12.0 \
awscli==1.11.76 \
ansible==2.4.2.0
- run:
name: Save Vault Password to File
command: echo $ANSIBLE_VAULT_PASS > .vault-pass.txt
- run:
name: Decrypt .env
command: |
ansible-vault decrypt .circleci/envs --vault-password-file .vault-pass.txt
- run:
name: Move .env
command: rm -f .env && mv .circleci/envs .env
- restore_cache:
keys:
- v1-{{ .Branch }}
paths:
- /caches/app.tar
- run:
name: Load Docker image layer cache
command: |
set +o pipefail
docker load -i /caches/app.tar | true
- run:
name: Build application Docker image
command: |
docker build --cache-from=app -t app .
- run:
name: Save Docker image layer cache
command: |
mkdir -p /caches
docker save -o /caches/app.tar app
- save_cache:
key: v1-{{ .Branch }}-{{ epoch }}
paths:
- /caches/app.tar
- deploy:
name: Push application Docker image
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
login="$(aws ecr get-login --region $ECR_REGION)"
${login}
docker tag app "${ECR_ENDPOINT}:${CIRCLE_SHA1}"
docker push "${ECR_ENDPOINT}:${CIRCLE_SHA1}"
fi

关于docker - Circleci 2.0 基于 Dockerfile 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49929471/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com