我正在尝试在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
答案 0 :(得分:0)
做了一些谷歌搜索,然后我想到了其他一些堆栈溢出情况,这些情况都处理了您的错误中的警告消息。具体来说,这3条消息:
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 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
这是我发现的情况:
When to turn off Transparent Huge Pages for redis
Solving Redis warnings on overcommit_memory and Transparent Huge Pages for Ubuntu 16.04 on EC2
What's "tcp-backlog" in redis.conf
您的问题可能与打开透明大页面(THP)有关。
按照“何时关闭Redis的透明大页面”一文中的答案进行操作,您应该会很好。另外,这是redis的延迟问题排查指南。
答案 1 :(得分:0)
在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
您的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容器,以便他们可以通信。