/
Flyway Docker Compose Testing

Flyway Docker Compose Testing

docker-compose-test.yml

docker-compose-test.yml
# # ===========LICENSE_START==================================================== # Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. # Modifications Copyright (C) 2021 Bell Canada. All rights reserved. # ============================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============LICENSE_END===================================================== # version: '2' services: mariadb: image: nexus3.onap.org:10001/mariadb:10.5.8 container_name: mariadb hostname: mariadb command: ['--lower-case-table-names=1', '--wait_timeout=28800'] env_file: config/db/db.conf environment: MYSQL_DB: policyadmin volumes: - ./config/db:/docker-entrypoint-initdb.d:ro expose: - 3306 flyway: build: context: . dockerfile: Dockerfile container_name: flyway depends_on: - mariadb hostname: flyway expose: - 2468 env_file: config/db/db.conf environment: MYSQL_DB: policyadmin volumes: - ./config/db/db.conf:/flyway/conf/db.conf:ro - ./config/flyway/sql:/flyway/sql - ./flyway_policy_init.sh:/flyway/bin/flyway_policy_init.sh:ro - ./socket_listener.py:/flyway/bin/socket_listener.py:ro - ./wait_for_port.sh:/flyway/bin/wait_for_port.sh:ro entrypoint: /flyway/bin/wait_for_port.sh command: [ '-c', '/flyway/bin/flyway_policy_init.sh', 'mariadb', '3306' ]



Dockerfile

Dockerfile
FROM flyway/flyway:latest USER root RUN apt-get update && apt-get install -y netcat RUN apt-get update && apt-get install -y python3





flyway_policy_init.sh

flyway_policy_init.sh
#!/bin/sh # ============LICENSE_START==================================================== # Copyright (C) 2021. Nordix Foundation. All rights reserved. # ============================================================================= # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # SPDX-License-Identifier: Apache-2.0 # ============LICENSE_END====================================================== flyway -user=${MYSQL_USER} -password=${MYSQL_PASSWORD} -url=jdbc:mariadb://mariadb:3306/${MYSQL_DB} migrate flyway -user=${MYSQL_USER} -password=${MYSQL_PASSWORD} -url=jdbc:mariadb://mariadb:3306/${MYSQL_DB} info /flyway/bin/socket_listener.py 2468 exit 0



socket_listener.py

socket_listener.py



Copy your schema creation script to config/flyway/sql/V1__Create_Policy_Tables.sql

Run docker-compose -f docker-compose-test.yml up



Creating network "csit_default" with the default driver
Creating mariadb ... done
Creating flyway ... done
Attaching to mariadb, flyway
flyway | Waiting for mariadb port 3306...
flyway | nc: connect to mariadb port 3306 (tcp) failed: Connection refused
mariadb | 2021-06-24 08:07:43+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.8+maria~focal started.
mariadb | 2021-06-24 08:07:43+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mariadb | 2021-06-24 08:07:43+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.5.8+maria~focal started.
mariadb | 2021-06-24 08:07:43+00:00 [Note] [Entrypoint]: Initializing database files
flyway | .nc: connect to mariadb port 3306 (tcp) failed: Connection refused
mariadb |
mariadb |
mariadb | PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
mariadb | To do so, start the server, then issue the following commands:
mariadb |
mariadb | '/usr/bin/mysqladmin' -u root password 'new-password'
mariadb | '/usr/bin/mysqladmin' -u root -h password 'new-password'
mariadb |
mariadb | Alternatively you can run:
mariadb | '/usr/bin/mysql_secure_installation'
mariadb |
mariadb | which will also give you the option of removing the test
mariadb | databases and anonymous user created by default. This is
mariadb | strongly recommended for production servers.
mariadb |
mariadb | See the MariaDB Knowledgebase at https://mariadb.com/kb or the
mariadb | MySQL manual for more instructions.
mariadb |
mariadb | Please report any problems at https://mariadb.org/jira
mariadb |
mariadb | The latest information about MariaDB is available at https://mariadb.org/.
mariadb | You can find additional information about the MySQL part at:
mariadb | https://dev.mysql.com
mariadb | Consider joining MariaDB's strong and vibrant community:
mariadb | https://mariadb.org/get-involved/
mariadb |
mariadb | 2021-06-24 08:07:45+00:00 [Note] [Entrypoint]: Database files initialized
mariadb | 2021-06-24 08:07:45+00:00 [Note] [Entrypoint]: Starting temporary server
mariadb | 2021-06-24 08:07:45+00:00 [Note] [Entrypoint]: Waiting for server startup
mariadb | 2021-06-24 8:07:45 0 [Note] mysqld (mysqld 10.5.8-MariaDB-1:10.5.8+maria~focal) starting as process 110 ...
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: Using Linux native AIO
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: Uses event mutexes
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: Number of pools: 1
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
mariadb | 2021-06-24 8:07:45 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: Completed initialization of buffer pool
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: 128 rollback segments are active.
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: Creating shared tablespace for temporary tables
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: 10.5.8 started; log sequence number 45118; transaction id 20
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mariadb | 2021-06-24 8:07:45 0 [Note] InnoDB: Buffer pool(s) load completed at 210624 8:07:45
mariadb | 2021-06-24 8:07:45 0 [Note] Plugin 'FEEDBACK' is disabled.
mariadb | 2021-06-24 8:07:45 0 [Warning] 'user' entry 'root@mariadb' ignored in --skip-name-resolve mode.
mariadb | 2021-06-24 8:07:45 0 [Warning] 'proxies_priv' entry '@% root@mariadb' ignored in --skip-name-resolve mode.
mariadb | 2021-06-24 8:07:45 0 [Note] Reading of all Master_info entries succeeded
mariadb | 2021-06-24 8:07:45 0 [Note] Added new Master_info '' to hash table
mariadb | 2021-06-24 8:07:45 0 [Note] mysqld: ready for connections.
mariadb | Version: '10.5.8-MariaDB-1:10.5.8+maria~focal' socket: '/run/mysqld/mysqld.sock' port: 0 mariadb.org binary distribution
flyway | .nc: connect to mariadb port 3306 (tcp) failed: Connection refused
mariadb | 2021-06-24 08:07:46+00:00 [Note] [Entrypoint]: Temporary server started.
flyway | .nc: connect to mariadb port 3306 (tcp) failed: Connection refused
mariadb | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
mariadb | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
flyway | .nc: connect to mariadb port 3306 (tcp) failed: Connection refused
mariadb | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
mariadb | 2021-06-24 8:07:48 5 [Warning] 'proxies_priv' entry '@% root@mariadb' ignored in --skip-name-resolve mode.
mariadb | 2021-06-24 08:07:48+00:00 [Note] [Entrypoint]: Creating user policy_user
mariadb |
mariadb | 2021-06-24 08:07:48+00:00 [Warn] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/db.conf
mariadb |
mariadb | 2021-06-24 08:07:48+00:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/db.sh
mariadb | #!/bin/bash -xv
mariadb | # Copyright 2019,2021 AT&T Intellectual Property. All rights reserved
mariadb | #
mariadb | # Licensed under the Apache License, Version 2.0 (the "License");
mariadb | # you may not use this file except in compliance with the License.
mariadb | # You may obtain a copy of the License at
mariadb | #
mariadb | # http://www.apache.org/licenses/LICENSE-2.0
mariadb | #
mariadb | # Unless required by applicable law or agreed to in writing, software
mariadb | # distributed under the License is distributed on an "AS IS" BASIS,
mariadb | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mariadb | # See the License for the specific language governing permissions and
mariadb | # limitations under the License.
mariadb |
mariadb | for db in support onap_sdk log migration operationshistory10 pooling policyadmin operationshistory
mariadb | do
mariadb | mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" --execute "CREATE DATABASE IF NOT EXISTS ${db};"
mariadb | mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" --execute "GRANT ALL PRIVILEGES ON \`${db}\`.* TO '${MYSQL_USER}'@'%' ;"
mariadb | done
mariadb | + for db in support onap_sdk log migration operationshistory10 pooling policyadmin operationshistory
mariadb | + mysql -uroot -p****** --execute 'CREATE DATABASE IF NOT EXISTS support;'
mariadb | + mysql -uroot -p****** --execute 'GRANT ALL PRIVILEGES ON `support`.* TO '\''policy_user'\''@'\''%'\'' ;'
mariadb | + for db in support onap_sdk log migration operationshistory10 pooling policyadmin operationshistory
mariadb | + mysql -uroot -p****** --execute 'CREATE DATABASE IF NOT EXISTS onap_sdk;'
mariadb | + mysql -uroot -p****** --execute 'GRANT ALL PRIVILEGES ON `onap_sdk`.* TO '\''policy_user'\''@'\''%'\'' ;'
mariadb | + for db in support onap_sdk log migration operationshistory10 pooling policyadmin operationshistory
mariadb | + mysql -uroot -p****** --execute 'CREATE DATABASE IF NOT EXISTS log;'
mariadb | + mysql -uroot -p****** --execute 'GRANT ALL PRIVILEGES ON `log`.* TO '\''policy_user'\''@'\''%'\'' ;'
mariadb | + for db in support onap_sdk log migration operationshistory10 pooling policyadmin operationshistory
mariadb | + mysql -uroot -p****** --execute 'CREATE DATABASE IF NOT EXISTS migration;'
mariadb | + mysql -uroot -p****** --execute 'GRANT ALL PRIVILEGES ON `migration`.* TO '\''policy_user'\''@'\''%'\'' ;'
mariadb | + for db in support onap_sdk log migration operationshistory10 pooling policyadmin operationshistory
mariadb | + mysql -uroot -p****** --execute 'CREATE DATABASE IF NOT EXISTS operationshistory10;'
mariadb | + mysql -uroot -p****** --execute 'GRANT ALL PRIVILEGES ON `operationshistory10`.* TO '\''policy_user'\''@'\''%'\'' ;'
flyway | .nc: connect to mariadb port 3306 (tcp) failed: Connection refused
mariadb | + for db in support onap_sdk log migration operationshistory10 pooling policyadmin operationshistory
mariadb | + mysql -uroot -p****** --execute 'CREATE DATABASE IF NOT EXISTS pooling;'
mariadb | + mysql -uroot -p****** --execute 'GRANT ALL PRIVILEGES ON `pooling`.* TO '\''policy_user'\''@'\''%'\'' ;'
mariadb | + for db in support onap_sdk log migration operationshistory10 pooling policyadmin operationshistory
mariadb | + mysql -uroot -p****** --execute 'CREATE DATABASE IF NOT EXISTS policyadmin;'
mariadb | + mysql -uroot -p****** --execute 'GRANT ALL PRIVILEGES ON `policyadmin`.* TO '\''policy_user'\''@'\''%'\'' ;'
mariadb | + for db in support onap_sdk log migration operationshistory10 pooling policyadmin operationshistory
mariadb | + mysql -uroot -p****** --execute 'CREATE DATABASE IF NOT EXISTS operationshistory;'
mariadb | + mysql -uroot -p****** --execute 'GRANT ALL PRIVILEGES ON `operationshistory`.* TO '\''policy_user'\''@'\''%'\'' ;'
mariadb |
mariadb | mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" --execute "FLUSH PRIVILEGES;"
mariadb | + mysql -uroot -p****** --execute 'FLUSH PRIVILEGES;'
mariadb | 2021-06-24 8:07:48 23 [Warning] 'proxies_priv' entry '@% root@mariadb' ignored in --skip-name-resolve mode.
mariadb |
mariadb | 2021-06-24 08:07:48+00:00 [Note] [Entrypoint]: Stopping temporary server
mariadb | 2021-06-24 8:07:48 0 [Note] mysqld (initiated by: root[root] @ localhost []): Normal shutdown
mariadb | 2021-06-24 8:07:48 0 [Note] Event Scheduler: Purging the queue. 0 events
mariadb | 2021-06-24 8:07:48 0 [Note] InnoDB: FTS optimize thread exiting.
mariadb | 2021-06-24 8:07:48 0 [Note] InnoDB: Starting shutdown...
mariadb | 2021-06-24 8:07:48 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
mariadb | 2021-06-24 8:07:48 0 [Note] InnoDB: Buffer pool(s) dump completed at 210624 8:07:48
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: Shutdown completed; log sequence number 45130; transaction id 21
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
mariadb | 2021-06-24 8:07:49 0 [Note] mysqld: Shutdown complete
mariadb |
flyway | .nc: connect to mariadb port 3306 (tcp) failed: Connection refused
mariadb | 2021-06-24 08:07:49+00:00 [Note] [Entrypoint]: Temporary server stopped
mariadb |
mariadb | 2021-06-24 08:07:49+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
mariadb |
mariadb | 2021-06-24 8:07:49 0 [Note] mysqld (mysqld 10.5.8-MariaDB-1:10.5.8+maria~focal) starting as process 1 ...
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: Using Linux native AIO
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: Uses event mutexes
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: Number of pools: 1
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
mariadb | 2021-06-24 8:07:49 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: Completed initialization of buffer pool
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: 128 rollback segments are active.
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: Creating shared tablespace for temporary tables
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: 10.5.8 started; log sequence number 45130; transaction id 20
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mariadb | 2021-06-24 8:07:49 0 [Note] Plugin 'FEEDBACK' is disabled.
mariadb | 2021-06-24 8:07:49 0 [Note] InnoDB: Buffer pool(s) load completed at 210624 8:07:49
mariadb | 2021-06-24 8:07:49 0 [Note] Server socket created on IP: '::'.
mariadb | 2021-06-24 8:07:49 0 [Warning] 'proxies_priv' entry '@% root@mariadb' ignored in --skip-name-resolve mode.
mariadb | 2021-06-24 8:07:49 0 [Note] Reading of all Master_info entries succeeded
mariadb | 2021-06-24 8:07:49 0 [Note] Added new Master_info '' to hash table
mariadb | 2021-06-24 8:07:49 0 [Note] mysqld: ready for connections.
mariadb | Version: '10.5.8-MariaDB-1:10.5.8+maria~focal' socket: '/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
flyway | .Connection to mariadb 3306 port [tcp/*] succeeded!
mariadb | 2021-06-24 8:07:50 3 [Warning] Aborted connection 3 to db: 'unconnected' user: 'unauthenticated' host: '172.20.0.3' (This connection closed normally without authentication)
flyway | Flyway Community Edition 7.10.0 by Redgate
flyway | Database: jdbc:mariadb://mariadb:3306/policyadmin (MariaDB 10.5)
flyway | Successfully validated 1 migration (execution time 00:00.024s)
flyway | Creating Schema History table `policyadmin`.`flyway_schema_history` ...
flyway | Current version of schema `policyadmin`: << Empty Schema >>
flyway | Migrating schema `policyadmin` to version "1 - Create Policy Tables"
flyway | Successfully applied 1 migration to schema `policyadmin`, now at version v1 (execution time 00:00.790s)
flyway | Flyway Community Edition 7.10.0 by Redgate
flyway | Database: jdbc:mariadb://mariadb:3306/policyadmin (MariaDB 10.5)
flyway | Schema version: 1
flyway |
flyway | +-----------+---------+----------------------+------+---------------------+---------+
flyway | | Category | Version | Description | Type | Installed On | State |
flyway | +-----------+---------+----------------------+------+---------------------+---------+
flyway | | Versioned | 1 | Create Policy Tables | SQL | 2021-06-24 08:07:53 | Success |
flyway | +-----------+---------+----------------------+------+---------------------+---------+
flyway |

Related content

Liquibase Docker Compose Testing
Liquibase Docker Compose Testing
More like this
Creating an Instance of SDN-R using docker-compose
Creating an Instance of SDN-R using docker-compose
More like this
Running Blueprints Controller Microservice Locally
Running Blueprints Controller Microservice Locally
More like this
Running Blueprints Processor Microservice Locally
Running Blueprints Processor Microservice Locally
More like this
dcae-cli Tool
dcae-cli Tool
More like this
CPS Configuration
CPS Configuration
More like this