GitLab CI 允许向项目添加自定义变量。
它允许使用类型的秘密变量,file
其中我指定了一个作为变量名称的密钥和作为文件内容的值(例如证书的内容)
然后在管道执行期间,内容将保存为临时文件,调用变量名称将返回创建文件的路径。
最终,我需要将此文件复制到构建项目时创建的 Docker 容器中。(docker build ...
在yml中)
当如果变量作品测试,我想echo $VARIABLE
在.gitlab-ci.yml
和它的作品,临时文件的路径返回。但是在RUN echo $VARIABLE
in 中执行时Dockerfile
,它是空的。因此我也不能使用ADD $VARIABLE /tmp/
这是我的目标。
有没有办法解决这个问题并使这个文件可供Dockerfile
? 我是 Docker 和 GitLab 的新手,不知道还能去哪里找。
我正在学习如何使用 Azure 函数并在其中使用我的网页抓取脚本。
它使用 BeautifulSoup (bs4) 和 pymysql 模块。
当我按照 MS 指南在虚拟环境中本地尝试时,它工作正常:
但是,当我创建函数 App 并向其发布脚本时,Azure Functions 日志给出以下错误:
Failure Exception: ModuleNotFoundError: No module named 'pymysql'
。
尝试导入它时一定会发生这种情况。
我真的不知道如何继续,我应该在哪里指定需要安装哪些模块?
python python-module azure azure-functions azure-function-app
我需要使用官方的 PowerShell Core Docker 映像来运行 Docker 容器并使其执行 PowerShell 脚本文件。
我知道可以使用 Dockerfile 和 Docker 构建来完成,但在这种情况下不能使用它。
通过阅读文档,我想出了这个,但它似乎不起作用:
docker run -it --rm --entrypoint "/tmp/test.ps1" repo/powershell:latest
docker: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"/tmp/test.ps1\": stat /tmp/test.ps1: no such file or directory": unknown.
ERRO[0001] error waiting for container: context canceled
Run Code Online (Sandbox Code Playgroud)
错误似乎表明它找不到该文件,但stat "/tmp/test.ps1"
手动运行时它工作正常。
我觉得pwsh
还应该指定二进制文件,但找不到如何执行此操作的方法。
我正在尝试配置 Terraform,以便它使用 AWS Secrets 的环境变量。
terraform.tfvars:
access_key = "${var.TF_VAR_AWS_AK}"
secret_key = "${var.TF_VAR_AWS_SK}"
aws_region = "eu-north-1"
Run Code Online (Sandbox Code Playgroud)
主要.tf:
provider "aws" {
region = "${var.aws_region}"
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
}
Run Code Online (Sandbox Code Playgroud)
在控制台中(在 Windows 10 上):
set TF_VAR_AWS_AK = asd12345asd12345
set TF_VAR_AWS_SK = asd12345asd12345
terraform plan
Run Code Online (Sandbox Code Playgroud)
错误信息:
Error: Variables not allowed
on terraform.tfvars line 1:
1: access_key = "${var.TF_VAR_AWS_AK}"
Variables may not be used here.
Error: Variables not allowed
on terraform.tfvars line 2:
2: secret_key = "${var.TF_VAR_AWS_SK}"
Variables may not be used here. …
Run Code Online (Sandbox Code Playgroud) 我遇到了这个错误:
Inappropriate value for attribute "vpc_zone_identifier": element 0: string required.
变量应该是字符串列表,所以元素 0 应该是字符串。
这是代码:
专有网络模块:
resource "aws_subnet" "terraform-pub-sn" {
count = "${length(data.aws_availability_zones.all.names)}"
vpc_id = "${aws_vpc.terraform-vpc.id}"
cidr_block = "${element(var.vpc_subnet_cidr, count.index)}"
availability_zone = "${data.aws_availability_zones.all.names[count.index]}"
}
Run Code Online (Sandbox Code Playgroud)
输出:
output "terraform_subnet_ids" {
value = ["${aws_subnet.terraform-pub-sn.*.id}"]
}
Run Code Online (Sandbox Code Playgroud)
主文件:
module "auto_scaling_group" {
source = "./modules/AutoScalingGroup"
terraform_subnet_ids = ["${module.vpc.terraform_subnet_ids}"]
}
Run Code Online (Sandbox Code Playgroud)
ASG 模块:
variable "terraform_subnet_ids"{}
resource "aws_autoscaling_group" "terraform-asg" {
vpc_zone_identifier = ["${var.terraform_subnet_ids}"]
...
}
Run Code Online (Sandbox Code Playgroud)
我花了半天时间试图解决这个问题,不知道还能尝试什么以及应该如何定义它。AFAIK 添加 [] 将使变量成为一个字符串列表,当它选择元素 0 并返回错误时,元素在技术上应该是一个字符串,所以不知道问题是什么。也许有一种方法可以即时检查它是什么?
完整的错误在这里:
Error: Incorrect attribute value type
on modules\AutoScalingGroup\asg.tf line …
Run Code Online (Sandbox Code Playgroud) 尝试制作一个简单的 GitLab 管道,为 Alpine Linux + Openshift CLI 构建 Docker 镜像。
这是代码:
FROM frolvlad/alpine-glibc:latest
MAINTAINER Daniel Widerin <daniel@widerin.net>
ENV OC_VERSION=v3.11.0 \
OC_TAG_SHA=0cbc58b \
BUILD_DEPS='tar gzip' \
RUN_DEPS='curl ca-certificates gettext'
RUN apk --no-cache add $BUILD_DEPS $RUN_DEPS && \
curl -sLo /tmp/oc.tar.gz https://github.com/openshift/origin/releases/download/${OC_VERSION}/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit.tar.gz && \
tar xzvf /tmp/oc.tar.gz -C /tmp/ && \
mv /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit/oc /usr/local/bin/ && \
rm -rf /tmp/oc.tar.gz /tmp/openshift-origin-client-tools-${OC_VERSION}-${OC_TAG_SHA}-linux-64bit && \
apk del $BUILD_DEPS
CMD ["/bin/sh"]
Run Code Online (Sandbox Code Playgroud)
现在由于某种原因,在运行管道时,它会卡在curl
下载 openshift 存档的部分上。
Status: Downloaded newer image for frolvlad/alpine-glibc:latest
---> 38dd85a430e8
Step …
Run Code Online (Sandbox Code Playgroud) 我是 GitLab 的新手,不确定这是否可行,我已经在本地设置了 GitLab 并正在运行,还有 Artifactory 私人存储库。
我总是使用 DinD 配置,使用 Docker 作为带有 DinD 服务的主映像,然后在各个阶段登录并从私有存储库中提取不同的映像。
但我听说没有 DinD 也可以做到这一点,从而缩短执行时间。所需的图像是在阶段开始时拉取的。
而不是这个:
image: docker:latest
services:
- docker:18.09.8-dind
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://localhost:2375
stages:
- run_script
run_script:
stage:
run_script
script:
- docker login -u $DOCKER_TECHNICAL_USER -p $DOCKER_TECHNICAL_USER_PASSWORD $DOCKER_REGISTRY_URL
- docker pull artifactory.example.com:5000/repo/powershell-core:6.3
- docker run -it artifactory.example.com:5000/repo/powershell-core:6.3 pwsh -command "get-process"
Run Code Online (Sandbox Code Playgroud)
我想这样做(整个yml):
stages:
- run_script
run_script:
before_script:
- docker login -u $DOCKER_TECHNICAL_USER -p $DOCKER_TECHNICAL_USER_PASSWORD $DOCKER_REGISTRY_URL
image: artifactory.example.com:5000/repo/powershell-core:6.3
stage:
run_script
script:
- pwsh -command "get-process"
Run Code Online (Sandbox Code Playgroud)
如果我尝试这样做,它会说它无法进行身份验证:
ERROR: …
Run Code Online (Sandbox Code Playgroud) continuous-integration gitlab gitlab-ci gitlab-ci-runner devops
devops ×3
docker ×3
gitlab ×3
gitlab-ci ×3
terraform ×2
azure ×1
docker-run ×1
dockerfile ×1
powershell ×1
python ×1