Bitbucket Pipelines - 访问另一个容器
Bitbucket Pipelines - access to another container
这是我的 bitbucket-pipelines.yml 配置文件:
# This is a sample build configuration for Javascript.
# Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: node:6.9.5
pipelines:
default:
- step:
script:
# Step 1 : Install yarn with the easy way : https://yarnpkg.com/en/docs/install#alternatives-tab
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 0.22.0
# Step 2: Belived https://confluence.atlassian.com/bitbucket/javascript-node-js-with-bitbucket-pipelines-873891287.html#Javascript(Node.js)withBitbucketPipelines-ManagingdependencieswithYarn
# PATH variable should change like they said
- export PATH=$HOME/.yarn/bin:$PATH
# Step 3: Install app dependencies
- yarn install
#Allow to test app in production context
- export NODE_ENV=production
#Allow to specify the JWT TOKEN Signature (and not use OAuth0)
- export SECRET_SIGNATURE_JWT_TOKEN=pokémon47
# prepare PostgreSQL
# - psql -U "postgres" -c "CREATE DATABASE custom_db" # create a new database
# - psql -U "postgres" -c "CREATE USER custom_user WITH PASSWORD 'custom_pass'" # create a new user : custom_user
# - psql -U "postgres" -d "custom_db" -f sql/database_tables.sql # create tables
# - psql -U "postgres" -d "custom_db" -f sql/database_grant.sql # give him the credentials
# - psql -U "postgres" -d "custom_db" -f sql/test_insert.sql # add basic data inside the database : some parkings and reasons
#run the test with database
- npm test
services:
- postgres
definitions:
services:
postgres:
image: postgres:9.3
我想像使用 psql 一样初始化数据库。
唯一的问题:如何访问容器?
我尝试了我知道的经典命令 docker :
docker ps
docker exec -it myContainer bash
结果:
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
(而且我无权在此 CI 上启用 docker 守护进程)
我使用的文档:https://confluence.atlassian.com/bitbucket/use-services-and-databases-in-bitbucket-pipelines-874786688.html and https://confluence.atlassian.com/bitbucket/test-with-databases-in-bitbucket-pipelines-856697462.html#TestwithdatabasesinBitbucketPipelines-PostgreSQL–defaultuser
PS:如果您想要来自 Postgresql 容器的日志:
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... ok
creating template1 database in /var/lib/postgresql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
syncing data to disk ... ok
Success. You can now start the database server using:
postgres -D /var/lib/postgresql/data
or
pg_ctl -D /var/lib/postgresql/data -l logfile start
****************************************************
WARNING: No password has been set for the database.
This will allow anyone with access to the
Postgres port to access your database. In
Docker's default configuration, this is
effectively any other container on the same
system.
Use "-e POSTGRES_PASSWORD=password" to set
it in "docker run".
****************************************************
waiting for server to start....LOG: database system was shut down at 2017-04-20 12:50:43 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
done
server started
ALTER ROLE
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
LOG: received fast shutdown request
LOG: aborting any active transactions
waiting for server to shut down...LOG: autovacuum launcher shutting down
LOG: shutting down
.LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
LOG: database system was shut down at 2017-04-20 12:50:45 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
LOG: received smart shutdown request
LOG: autovacuum launcher shutting down
LOG: shutting down
LOG: database system is shut down
Bitbucket 文档尽量清晰明了,但并未尝试帮助用户:
PostgreSQL will be available on localhost:5432
问题是,psql
没有像您预期的那样工作。它们的默认行为是连接到文件套接字 (/var/run/postgresql/.s.PGSQL.5432
),而不是 localhost
.
您必须设置主机参数才能连接:psql -h localhost
这是我的 bitbucket-pipelines.yml 配置文件:
# This is a sample build configuration for Javascript.
# Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: node:6.9.5
pipelines:
default:
- step:
script:
# Step 1 : Install yarn with the easy way : https://yarnpkg.com/en/docs/install#alternatives-tab
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 0.22.0
# Step 2: Belived https://confluence.atlassian.com/bitbucket/javascript-node-js-with-bitbucket-pipelines-873891287.html#Javascript(Node.js)withBitbucketPipelines-ManagingdependencieswithYarn
# PATH variable should change like they said
- export PATH=$HOME/.yarn/bin:$PATH
# Step 3: Install app dependencies
- yarn install
#Allow to test app in production context
- export NODE_ENV=production
#Allow to specify the JWT TOKEN Signature (and not use OAuth0)
- export SECRET_SIGNATURE_JWT_TOKEN=pokémon47
# prepare PostgreSQL
# - psql -U "postgres" -c "CREATE DATABASE custom_db" # create a new database
# - psql -U "postgres" -c "CREATE USER custom_user WITH PASSWORD 'custom_pass'" # create a new user : custom_user
# - psql -U "postgres" -d "custom_db" -f sql/database_tables.sql # create tables
# - psql -U "postgres" -d "custom_db" -f sql/database_grant.sql # give him the credentials
# - psql -U "postgres" -d "custom_db" -f sql/test_insert.sql # add basic data inside the database : some parkings and reasons
#run the test with database
- npm test
services:
- postgres
definitions:
services:
postgres:
image: postgres:9.3
我想像使用 psql 一样初始化数据库。 唯一的问题:如何访问容器?
我尝试了我知道的经典命令 docker :
docker ps
docker exec -it myContainer bash
结果:
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
(而且我无权在此 CI 上启用 docker 守护进程)
我使用的文档:https://confluence.atlassian.com/bitbucket/use-services-and-databases-in-bitbucket-pipelines-874786688.html and https://confluence.atlassian.com/bitbucket/test-with-databases-in-bitbucket-pipelines-856697462.html#TestwithdatabasesinBitbucketPipelines-PostgreSQL–defaultuser
PS:如果您想要来自 Postgresql 容器的日志:
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... ok
creating template1 database in /var/lib/postgresql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
syncing data to disk ... ok
Success. You can now start the database server using:
postgres -D /var/lib/postgresql/data
or
pg_ctl -D /var/lib/postgresql/data -l logfile start
****************************************************
WARNING: No password has been set for the database.
This will allow anyone with access to the
Postgres port to access your database. In
Docker's default configuration, this is
effectively any other container on the same
system.
Use "-e POSTGRES_PASSWORD=password" to set
it in "docker run".
****************************************************
waiting for server to start....LOG: database system was shut down at 2017-04-20 12:50:43 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
done
server started
ALTER ROLE
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
LOG: received fast shutdown request
LOG: aborting any active transactions
waiting for server to shut down...LOG: autovacuum launcher shutting down
LOG: shutting down
.LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
LOG: database system was shut down at 2017-04-20 12:50:45 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
LOG: received smart shutdown request
LOG: autovacuum launcher shutting down
LOG: shutting down
LOG: database system is shut down
Bitbucket 文档尽量清晰明了,但并未尝试帮助用户:
PostgreSQL will be available on localhost:5432
问题是,psql
没有像您预期的那样工作。它们的默认行为是连接到文件套接字 (/var/run/postgresql/.s.PGSQL.5432
),而不是 localhost
.
您必须设置主机参数才能连接:psql -h localhost