Gitlab + liqubase
Posted
技术标签:
【中文标题】Gitlab + liqubase【英文标题】: 【发布时间】:2020-05-13 01:32:51 【问题描述】:这个问题很简单 在 gitlab 管道中执行 liquibase 迁移的最佳方法是什么
到目前为止我所拥有的 但似乎 gitlab services 立即执行 docker run,而 docker run 已经需要 db 迁移参数
image: docker:19.03.1
stages:
- build
- db-migration
- deploy
services:
- docker:19.03.1-dind
- liquibase/liquibase:latest
variables:
DOCKER_TLS_CERTDIR: "/certs"
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_IMAGE_PATH: $AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com
before_script:
- apk add --update python python-dev py-pip
- pip install awscli --upgrade
- $(aws ecr get-login --no-include-email --region $AWS_REGION | tr -d '\r')
build:
stage: build
script:
- docker build --tag $AWS_IMAGE_PATH/$CI_PROJECT_NAME:$CI_COMMIT_SHA --tag $AWS_IMAGE_PATH/$CI_PROJECT_NAME:latest .
- docker push $AWS_IMAGE_PATH/$CI_PROJECT_NAME:$CI_COMMIT_SHA
- docker push $AWS_IMAGE_PATH/$CI_PROJECT_NAME:latest
db-migration:
stage: db-migration
script:
- liquibase --changeLogFile=/src/main/resources/db/changelog/psql/changelog.yaml
--url="jdbc:postgresql://host:5432/db"
--username username --password $DB_PASSWORD update
deploy:
stage: deploy
script:
- echo "Deployed"
【问题讨论】:
【参考方案1】:db-migration:
image: openjdk:8-jre-alpine
stage: db-migration
script:
- INIT_PATH=`pwd`
- apk add bash
- mkdir /liquibase
- mkdir /Downloads
- cd /Downloads
- wget "https://github.com/liquibase/liquibase/releases/download/liquibase-parent-3.7.0/liquibase-3.7.0-bin.zip"
- wget "https://repo1.maven.org/maven2/org/postgresql/postgresql/42.2.8/postgresql-42.2.8.jar"
- unzip liquibase-3.7.0-bin.zip -d /liquibase -q
- mv postgresql-42.2.8.jar /liquibase/lib/
- export PATH=$PATH:/liquibase
- liquibase --changeLogFile=$INIT_PATH/src/main/resources/db/changelog/psql/changelog.yaml
--url="jdbc:postgresql://host:port/db"
--username username --password $DB_PASSWORD update
only:
- master
【讨论】:
我认为使用已安装 liquibase 的 docker 映像可能是更好的解决方案。以上是关于Gitlab + liqubase的主要内容,如果未能解决你的问题,请参考以下文章