我正在尝试在 GCP 上设置 CI/CD 管道。我有一个使用 Redis 作为数据库的 NodeJS 应用程序。我正在尝试在 GCP 上配置 redis。
我已经尝试了下面的配置,但是一旦执行了redis步骤,它就会一直等待redis连接并且不会进行下一步,并且在一段时间后,构建超时。
Cloudbuild.yaml 文件:
steps:
- name: 'gcr.io/cloud-builders/npm'
args: ['install']
- name: 'redis'
env: ['REDISHOST=127.0.0.1', 'REDISPORT=6379']
- name: 'gcr.io/cloud-builders/npm'
args: ['test']
- name: "gcr.io/cloud-builders/gcloud"
args: ["app deploy"]
错误日志:
ERROR: context deadline exceeded
TIMEOUT
Finished Step #1
Step #1: 1:M 06 Sep 2019 18:43:09.317 # Redis is now ready to exit, bye bye...
Step #1: 1:M 06 Sep 2019 18:43:09.317 * DB saved on disk
Step #1: 1:M 06 Sep 2019 18:43:09.312 * Saving the final RDB snapshot before exiting.
Step #1: 1:M 06 Sep 2019 18:43:09.312 # User requested shutdown...
Step #1: 1:signal-handler (1567795389) Received SIGTERM scheduling shutdown...
Step #1: 1:M 06 Sep 2019 18:33:38.595 * Ready to accept connections
Step #1: 1:M 06 Sep 2019 18:33:38.595 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
Step #1: 1:M 06 Sep 2019 18:33:38.595 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
Step #1: 1:M 06 Sep 2019 18:33:38.595 # Server initialized
Step #1: 1:M 06 Sep 2019 18:33:38.595 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
Step #1: 1:M 06 Sep 2019 18:33:38.594 * Running mode=standalone, port=6379.
Step #1: 1:C 06 Sep 2019 18:33:38.592 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
Step #1: 1:C 06 Sep 2019 18:33:38.592 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
Step #1: 1:C 06 Sep 2019 18:33:38.592 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
Step #1: docker.io/library/redis:latest
Step #1: Status: Downloaded newer image for redis:latest
Step #1: Digest: sha256:0e67625224c1da47cb3270e7a861a83e332f708d3d89dde0cbed432c94824d9a
Step #1: 93e8c2071125: Pull complete
Step #1: 8e4f9890211f: Pull complete
Step #1: 8a9a85c968a2: Pull complete
Step #1: c1b01f4f76d9: Pull complete
在 Google Cloud Build 中,每个步骤都在一个单独的 Docker 容器中依次执行。在您的情况下,第二步启动等待连接的 redis 容器。构建“卡住”并超时。
在这种情况下,您可以使用 Docker compose 在后台运行 Redis 容器。你的cloudbuild.yaml
文件可能看起来像这样:
steps:
- name: 'gcr.io/cloud-builders/npm'
args: ['install']
- name: 'docker/compose:1.24.1' # you can use the version of your choice
args: ['up', '-d']
- name: 'gcr.io/cloud-builders/npm'
args: ['test']
env:
- 'HOST=redis' # name of the running container
- 'PORT=6379'
- name: "gcr.io/cloud-builders/gcloud"
args: ['app', 'deploy'] # NOTE THAT YOU HAVE TO PROVIDE THIS AS 2 PARAMETERS
Your docker-compose.yml文件可能看起来像这样:
version: '3'
services:
redis:
image: redis
network_mode: cloudbuild
container_name: redis
expose:
- 6379
请注意network_mode: cloudbuild
配置。据记录here:“每个构建步骤都将其容器附加到名为 cloudbuild 的本地 Docker 网络来运行”。我们指示 Docker Compose 在该网络中运行 redis 容器,以便它们可以进行通信。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)