Thursday 20 April 2017

Bitbucket Pipelines - access to another container

here is my bitbucket-pipelines.yml config file :

# 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

I would like to initialize the database like I want with psql. The only problem : How can I access the container ?

I tried the classical commands I know for docker :

docker ps

docker exec -it myContainer bash

Result:

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

(And I have no right to enable the docker daemon on this CI)

The documentation I used : 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: If you want the logs from Postgresql container:

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



via jacques y

No comments:

Post a Comment