Skip to content

Commit

Permalink
Enable e2e testing with docker-compose on GitLab (mattermost#17765)
Browse files Browse the repository at this point in the history
* Make testing with docker-compose work on GitLab.

* Comment heavy jobs.

* Make testing with docker-compose work on GitLab.

* Comment heavy jobs.

* Fix images

* Addressing review.
  • Loading branch information
metanerd authored Jun 23, 2021
1 parent 58d5d51 commit 0765f27
Show file tree
Hide file tree
Showing 15 changed files with 632 additions and 201 deletions.
7 changes: 1 addition & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,4 @@ workflows:
- check-store-layers
- check-mocks
- check-migrations
- test-schema:
requires:
- check-app-layers
- check-store-layers
- check-mocks
- check-migrations
# test-schema for master run in .gitlab-ci.yml
238 changes: 128 additions & 110 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
stages:
# - test
- test
- build
- publish
- create-vars
Expand All @@ -9,118 +9,136 @@ include:
- project: mattermost/ci/mattermost-server
ref: master
file: private.yml
# - local: .gitlab-ci/test.yml
# - local: .gitlab-ci/test-schema.yml

variables:
BUILD: "yes"
TEST: "no"

empty:
stage: create-vars
script:
- echo "empty"

#lint:
# image: $CI_REGISTRY/mattermost/ci/images/golangci-lint:v1.38.0
# stage: .pre
# script:
# - GO111MODULE=off GOBIN=$PWD/bin go get -u github.com/mattermost/mattermost-govet
# - make config-reset
# - make check-style #todo MM_VET_OPENSPEC_PATH='$CI_PROJECT_DIR/mattermost-api-reference/v4/html/static/mattermost-openapi-v4.yaml'
# timeout: 60 mins
# rules:
# - if: '$TEST == "yes"'
#
#layers:
# image: $CI_REGISTRY/mattermost/ci/images/mattermost-build-server:20201119_golang-1.15.5
# stage: .pre
# script:
# - make store-layers
# - if [[ -n $(git status --porcelain) ]]; then echo "Please update the store layers using make store-layers"; exit 1; fi
# - git reset --hard
# - make app-layers
# - if [[ -n $(git status --porcelain) ]]; then echo "Please update the app layers using make app-layers"; exit 1; fi
# - git reset --hard
# rules:
# - if: '$TEST == "yes"'
#
#test-postgres:
# extends: .test
# tags:
# - docker
# variables:
# MM_SQLSETTINGS_DATASOURCE: "postgres://mmuser:mostest@postgres:5432/mattermost_test?sslmode=disable&connect_timeout=10"
# MM_SQLSETTINGS_DRIVERNAME: postgres
# rules:
# - if: '$TEST == "yes"'
#
#test-mysql:
# extends: .test
# tags:
# - docker
# variables:
# MM_SQLSETTINGS_DATASOURCE: "mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4,utf8&multiStatements=true"
# MM_SQLSETTINGS_DRIVERNAME: mysql
# rules:
# - if: '$TEST == "yes"'
#
#test-schema-postgres:
# extends: .test-schema
# tags:
# - docker
# script:
# - echo "Creating databases"
# - docker-compose --no-ansi exec -T postgres sh -c 'exec echo "CREATE DATABASE migrated; CREATE DATABASE latest;" | exec psql -U mmuser mattermost_test'
# - echo "Importing postgres dump from version 5.0"
# - docker-compose --no-ansi exec -T postgres psql -U mmuser -d migrated < ../scripts/mattermost-postgresql-5.0.sql
# - >
# docker run -d -it --name server-postgres --net build_mm-test \
# --env-file="dotenv/test-schema-validation.env" \
# --env MM_SQLSETTINGS_DATASOURCE="postgres://mmuser:mostest@postgres:5432/migrated?sslmode=disable&connect_timeout=10" \
# --env MM_SQLSETTINGS_DRIVERNAME=postgres \
# -v $CI_PROJECT_DIR:/mattermost-server \
# -w /mattermost-server \
# mattermost/mattermost-build-server:20201119_golang-1.15.5 \
# bash -c "ulimit -n 8096; make ARGS='version' run-cli && make MM_SQLSETTINGS_DATASOURCE='postgres://mmuser:mostest@postgres:5432/latest?sslmode=disable&connect_timeout=10' ARGS='version' run-cli"
# - docker logs -f server-postgres
# - echo "Generating dump"
# - docker-compose --no-ansi exec -T postgres pg_dump --schema-only -d migrated -U mmuser > migrated.sql
# - docker-compose --no-ansi exec -T postgres pg_dump --schema-only -d latest -U mmuser > latest.sql
# - echo "Removing databases created for db comparison"
# - docker-compose --no-ansi exec -T postgres sh -c 'exec echo "DROP DATABASE migrated; DROP DATABASE latest;" | exec psql -U mmuser mattermost_test'
# - echo "Generating diff"
# - diff migrated.sql latest.sql > diff.txt && echo "Both schemas are same" || (echo "Schema mismatch" && cat diff.txt && exit 1)
# rules:
# - if: '$TEST == "yes"'
#
#test-schema-mysql:
# extends: .test-schema
# tags:
# - docker
# script:
# - echo "Creating databases"
# - docker-compose --no-ansi exec -T mysql mysql -uroot -pmostest -e "CREATE DATABASE migrated; CREATE DATABASE latest; GRANT ALL PRIVILEGES ON migrated.* TO mmuser; GRANT ALL PRIVILEGES ON latest.* TO mmuser"
# - echo "Importing mysql dump from version 5.0"
# - docker-compose --no-ansi exec -T mysql mysql -D migrated -uroot -pmostest < ../scripts/mattermost-mysql-5.0.sql
# - >
# docker run -d -it --name server-mysql --net build_mm-test \
# --env-file="dotenv/test-schema-validation.env" \
# --env MM_SQLSETTINGS_DATASOURCE="mmuser:mostest@tcp(mysql:3306)/migrated?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s" \
# --env MM_SQLSETTINGS_DRIVERNAME=mysql \
# -v $CI_PROJECT_DIR:/mattermost-server \
# -w /mattermost-server \
# mattermost/mattermost-build-server:20201119_golang-1.15.5 \
# bash -c "ulimit -n 8096; make ARGS='version' run-cli && make MM_SQLSETTINGS_DATASOURCE='mmuser:mostest@tcp(mysql:3306)/latest?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s' ARGS='version' run-cli"
# - docker logs -f server-mysql
# - echo "Ignoring known MySQL mismatch 'ChannelMembers.SchemeGuest'"
# - docker-compose --no-ansi exec -T mysql mysql -D migrated -uroot -pmostest -e "ALTER TABLE ChannelMembers DROP COLUMN SchemeGuest;" || echo "drop failed"
# - docker-compose --no-ansi exec -T mysql mysql -D latest -uroot -pmostest -e "ALTER TABLE ChannelMembers DROP COLUMN SchemeGuest;" || echo "drop failed"
# - echo "Generating dump"
# - docker-compose --no-ansi exec -T mysql mysqldump --skip-opt --no-data --compact -u root -pmostest migrated > migrated.sql
# - docker-compose --no-ansi exec -T mysql mysqldump --skip-opt --no-data --compact -u root -pmostest latest > latest.sql
# - echo "Removing databases created for db comparison"
# - docker-compose --no-ansi exec -T mysql mysql -uroot -pmostest -e 'DROP DATABASE migrated; DROP DATABASE latest'
# - echo "Generating diff"
# rules:
# - if: '$TEST == "yes"'
.lint: # Commenting this job, because it is run in CircleCI
image: $CI_REGISTRY/mattermost/ci/images/golangci-lint:v1.39.0-1
stage: test
script:
- GO111MODULE=off GOBIN=$PWD/bin go get -u github.com/mattermost/mattermost-govet
- make config-reset
- make check-style #todo MM_VET_OPENSPEC_PATH='$CI_PROJECT_DIR/mattermost-api-reference/v4/html/static/mattermost-openapi-v4.yaml'
timeout: 60 mins
rules:
- if: '$CI_COMMIT_REF_NAME == "master"'

.layers: # Commenting this job, because it is run in CircleCI
image: $CI_REGISTRY/mattermost/ci/images/mattermost-build-server:20201119_golang-1.15.5
stage: test
script:
- make store-layers
- if [[ -n $(git status --porcelain) ]]; then echo "Please update the store layers using make store-layers"; exit 1; fi
- git reset --hard
- make app-layers
- if [[ -n $(git status --porcelain) ]]; then echo "Please update the app layers using make app-layers"; exit 1; fi
- git reset --hard
rules:
- if: '$CI_COMMIT_REF_NAME == "master"'

.test-mysql: # Commenting this job, because it is run in CircleCI
stage: test
image: $CI_REGISTRY/mattermost/ci/images/mattermost-build-docker:19.03.14-1
services:
- name: $CI_REGISTRY/mattermost/ci/images/docker-dind:19.03.14-1
alias: docker
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
DOCKER_CONTENT_TRUST: 0
DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE: ""
before_script:
- docker login ${CI_REGISTRY} --username ${CI_REGISTRY_USER} --password ${CI_REGISTRY_PASSWORD}
script:
- export COMPOSE_PROJECT_NAME="${CI_PIPELINE_IID}mysql"
- export RACE_MODE=""
- time cat .gitlab-ci/scripts/test/mysql.sh | /bin/bash
artifacts:
when: always
reports:
junit: report.xml
paths:
- build/logs
timeout: 2 hours
tags:
- k8s-memory
rules:
- if: '$CI_COMMIT_REF_NAME == "master"'

.test-postgres: # Commenting this job, because it is run in CircleCI
stage: test
image: $CI_REGISTRY/mattermost/ci/images/mattermost-build-docker:19.03.14-1
services:
- name: $CI_REGISTRY/mattermost/ci/images/docker-dind:19.03.14-1
alias: docker
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
DOCKER_CONTENT_TRUST: 0
DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE: ""
before_script:
- docker login ${CI_REGISTRY} --username ${CI_REGISTRY_USER} --password ${CI_REGISTRY_PASSWORD}
script:
- export COMPOSE_PROJECT_NAME="${CI_PIPELINE_IID}postgres"
- export RACE_MODE=""
- time cat .gitlab-ci/scripts/test/postgres.sh | /bin/bash
artifacts:
when: always
reports:
junit: report.xml
paths:
- build/logs
timeout: 2 hours
tags:
- k8s-memory
rules:
- if: '$CI_COMMIT_REF_NAME == "master"'

test-schema-mysql:
stage: test
image: $CI_REGISTRY/mattermost/ci/images/mattermost-build-docker:19.03.14-1
services:
- name: $CI_REGISTRY/mattermost/ci/images/docker-dind:19.03.14-1
alias: docker
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
DOCKER_CONTENT_TRUST: 0
DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE: ""
before_script:
- docker login ${CI_REGISTRY} --username ${CI_REGISTRY_USER} --password ${CI_REGISTRY_PASSWORD}
script:
- export COMPOSE_PROJECT_NAME="${CI_PIPELINE_IID}schemamysql"
- time cat .gitlab-ci/scripts/test-schema/mysql.sh | /bin/bash
tags:
- k8s-memory
rules:
- if: '$CI_COMMIT_REF_NAME == "master"'

test-schema-postgres:
stage: test
image: $CI_REGISTRY/mattermost/ci/images/mattermost-build-docker:19.03.14-1
services:
- name: $CI_REGISTRY/mattermost/ci/images/docker-dind:19.03.14-1
alias: docker
variables:
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
DOCKER_CONTENT_TRUST: 0
DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE: ""
before_script:
- docker login ${CI_REGISTRY} --username ${CI_REGISTRY_USER} --password ${CI_REGISTRY_PASSWORD}
script:
- export COMPOSE_PROJECT_NAME="${CI_PIPELINE_IID}schemapostgres"
- time cat .gitlab-ci/scripts/test-schema/postgres.sh | /bin/bash
tags:
- k8s-memory
rules:
- if: '$CI_COMMIT_REF_NAME == "master"'
52 changes: 52 additions & 0 deletions .gitlab-ci/scripts/test-schema/mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
set -xe

echo $DOCKER_HOST
docker ps
DOCKER_NETWORK="${COMPOSE_PROJECT_NAME}"
DOCKER_COMPOSE_FILE="gitlab-dc.schemamysql.yml"
CONTAINER_SERVER="${COMPOSE_PROJECT_NAME}_server_1"
docker network create ${DOCKER_NETWORK}
ulimit -n 8096
cd ${CI_PROJECT_DIR}/build
docker-compose -f $DOCKER_COMPOSE_FILE run -d --rm start_dependencies
sleep 5
docker run --net ${DOCKER_NETWORK} ${CI_REGISTRY}/mattermost/ci/images/curl:7.59.0-1 sh -c "until curl --max-time 5 --output - http://mysql:3306; do echo waiting for mysql; sleep 5; done;"

echo "Creating databases"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T mysql mysql -uroot -pmostest -e "CREATE DATABASE migrated; CREATE DATABASE latest; GRANT ALL PRIVILEGES ON migrated.* TO mmuser; GRANT ALL PRIVILEGES ON latest.* TO mmuser"
echo "Importing mysql dump from version 5.0"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T mysql mysql -D migrated -uroot -pmostest < ${CI_PROJECT_DIR}/scripts/mattermost-mysql-5.0.sql
docker run -d -it --rm --name "${CONTAINER_SERVER}" --net ${DOCKER_NETWORK} \
--env-file="dotenv/test-schema-validation.env" \
--env MM_SQLSETTINGS_DATASOURCE="mmuser:mostest@tcp(mysql:3306)/migrated?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s" \
--env MM_SQLSETTINGS_DRIVERNAME=mysql \
-v $CI_PROJECT_DIR:/mattermost-server \
-w /mattermost-server \
${CI_REGISTRY}/mattermost/ci/images/mattermost-build-server:20201119_golang-1.15.5 \
bash -c "ulimit -n 8096; make ARGS='version' run-cli && make MM_SQLSETTINGS_DATASOURCE='mmuser:mostest@tcp(mysql:3306)/latest?charset=utf8mb4,utf8&readTimeout=30s&writeTimeout=30s' ARGS='version' run-cli"
docker logs -f "${CONTAINER_SERVER}"

echo "Ignoring known MySQL mismatch: ChannelMembers.SchemeGuest"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T mysql mysql -D migrated -uroot -pmostest -e "ALTER TABLE ChannelMembers DROP COLUMN SchemeGuest;"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T mysql mysql -D latest -uroot -pmostest -e "ALTER TABLE ChannelMembers DROP COLUMN SchemeGuest;"
echo "Ignoring known MySQL mismatch: ChannelMembers.MentionCountRoot and MsgCountRoot"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T mysql mysql -D migrated -uroot -pmostest -e "ALTER TABLE ChannelMembers DROP COLUMN MentionCountRoot;"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T mysql mysql -D latest -uroot -pmostest -e "ALTER TABLE ChannelMembers DROP COLUMN MentionCountRoot;"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T mysql mysql -D migrated -uroot -pmostest -e "ALTER TABLE ChannelMembers DROP COLUMN MsgCountRoot;"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T mysql mysql -D latest -uroot -pmostest -e "ALTER TABLE ChannelMembers DROP COLUMN MsgCountRoot;"
echo "Ignoring known MySQL mismatch: Channels.TotalMsgCountRoot"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T mysql mysql -D migrated -uroot -pmostest -e "ALTER TABLE Channels DROP COLUMN TotalMsgCountRoot;"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T mysql mysql -D latest -uroot -pmostest -e "ALTER TABLE Channels DROP COLUMN TotalMsgCountRoot;"

echo "Generating dump"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T mysql mysqldump --skip-opt --no-data --compact -u root -pmostest migrated > migrated.sql
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T mysql mysqldump --skip-opt --no-data --compact -u root -pmostest latest > latest.sql
echo "Removing databases created for db comparison"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T mysql mysql -uroot -pmostest -e 'DROP DATABASE migrated; DROP DATABASE latest'

echo "Generating diff"
diff migrated.sql latest.sql > diff.txt && echo "Both schemas are same" || (echo "Schema mismatch" && cat diff.txt && exit 1)

docker-compose -f $DOCKER_COMPOSE_FILE down
docker network remove ${DOCKER_NETWORK}
47 changes: 47 additions & 0 deletions .gitlab-ci/scripts/test-schema/postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -xe

echo $DOCKER_HOST
docker ps
DOCKER_NETWORK="${COMPOSE_PROJECT_NAME}"
DOCKER_COMPOSE_FILE="gitlab-dc.schemapostgres.yml"
CONTAINER_SERVER="${COMPOSE_PROJECT_NAME}_server_1"
docker network create ${DOCKER_NETWORK}
ulimit -n 8096
cd ${CI_PROJECT_DIR}/build
docker-compose -f $DOCKER_COMPOSE_FILE run -d --rm start_dependencies
timeout 90s bash -c "until docker exec ${COMPOSE_PROJECT_NAME}_postgres_1 pg_isready ; do sleep 5 ; done"

echo "Creating databases"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T postgres sh -c 'exec echo "CREATE DATABASE migrated; CREATE DATABASE latest;" | exec psql -U mmuser mattermost_test'
echo "Importing postgres dump from version 5.0"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T postgres psql -U mmuser -d migrated < ${CI_PROJECT_DIR}/scripts/mattermost-postgresql-5.0.sql
docker run -d -it --rm --name "${CONTAINER_SERVER}" --net ${DOCKER_NETWORK} \
--env-file="dotenv/test-schema-validation.env" \
--env MM_SQLSETTINGS_DATASOURCE="postgres://mmuser:mostest@postgres:5432/migrated?sslmode=disable&connect_timeout=10" \
--env MM_SQLSETTINGS_DRIVERNAME=postgres \
-v $CI_PROJECT_DIR:/mattermost-server \
-w /mattermost-server \
${CI_REGISTRY}/mattermost/ci/images/mattermost-build-server:20201119_golang-1.15.5 \
bash -c "ulimit -n 8096; make ARGS='version' run-cli && make MM_SQLSETTINGS_DATASOURCE='postgres://mmuser:mostest@postgres:5432/latest?sslmode=disable&connect_timeout=10' ARGS='version' run-cli"
docker logs -f "${CONTAINER_SERVER}"

echo "Ignoring known mismatch: ChannelMembers.MentionCountRoot"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T postgres sh -c 'exec echo "ALTER TABLE ChannelMembers DROP COLUMN MentionCountRoot;" | exec psql -U mmuser -d migrated'
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T postgres sh -c 'exec echo "ALTER TABLE ChannelMembers DROP COLUMN MentionCountRoot;" | exec psql -U mmuser -d latest'
echo "Ignoring known mismatch: ChannelMembers.MsgCountRoot and Channels.TotalMsgCountRoot"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T postgres sh -c 'exec echo "ALTER TABLE ChannelMembers DROP COLUMN MsgCountRoot;" | exec psql -U mmuser -d migrated'
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T postgres sh -c 'exec echo "ALTER TABLE ChannelMembers DROP COLUMN MsgCountRoot;" | exec psql -U mmuser -d latest'
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T postgres sh -c 'exec echo "ALTER TABLE Channels DROP COLUMN TotalMsgCountRoot;" | exec psql -U mmuser -d migrated'
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T postgres sh -c 'exec echo "ALTER TABLE Channels DROP COLUMN TotalMsgCountRoot;" | exec psql -U mmuser -d latest'

echo "Generating dump"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T postgres pg_dump --schema-only -d migrated -U mmuser > migrated.sql
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T postgres pg_dump --schema-only -d latest -U mmuser > latest.sql
echo "Removing databases created for db comparison"
docker-compose -f $DOCKER_COMPOSE_FILE exec -d -T postgres sh -c 'exec echo "DROP DATABASE migrated; DROP DATABASE latest;" | exec psql -U mmuser mattermost_test'
echo "Generating diff"
diff migrated.sql latest.sql > diff.txt && echo "Both schemas are same" || (echo "Schema mismatch" && cat diff.txt && exit 1)

docker-compose -f $DOCKER_COMPOSE_FILE down
docker network remove ${DOCKER_NETWORK}
Loading

0 comments on commit 0765f27

Please sign in to comment.