forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (159 loc) · 7.69 KB
/
esrupgrade-common.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: ESR Upgrade
on:
workflow_call:
inputs:
db-dump-url:
required: true
type: string
initial-version:
required: true
type: string
final-version:
required: true
type: string
env:
COMPOSE_PROJECT_NAME: ghactions
BUILD_IMAGE: mattermost/mattermost-enterprise-edition:${{ inputs.final-version }}
MYSQL_CONN_ARGS: -h localhost -P 3306 --protocol=tcp -ummuser -pmostest mattermost_test
DUMP_SERVER_NAME: esr.${{ inputs.initial-version }}-${{ inputs.final-version }}.dump.server.sql
DUMP_SCRIPT_NAME: esr.${{ inputs.initial-version }}-${{ inputs.final-version }}.dump.script.sql
MIGRATION_SCRIPT: esr.${{ inputs.initial-version }}-${{ inputs.final-version }}.mysql.up.sql
CLEANUP_SCRIPT: esr.${{ inputs.initial-version }}-${{ inputs.final-version }}.mysql.cleanup.sql
PREPROCESS_SCRIPT: esr.common.mysql.preprocess.sql
DIFF_NAME: esr.${{ inputs.initial-version }}-${{ inputs.final-version }}.diff
jobs:
esr-upgrade-server:
runs-on: ubuntu-latest-8-cores
timeout-minutes: 30
steps:
- name: Checkout mattermost project
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Run docker compose
run: |
cd server/build
docker compose --no-ansi run --rm start_dependencies
cat ../tests/test-data.ldif | docker compose --no-ansi exec -T openldap bash -c 'ldapadd -x -D "cn=admin,dc=mm,dc=test,dc=com" -w mostest';
docker compose --no-ansi exec -T minio sh -c 'mkdir -p /data/mattermost-test';
docker compose --no-ansi ps
- name: Wait for docker compose
run: |
until docker network inspect ghactions_mm-test; do echo "Waiting for Docker Compose Network..."; sleep 1; done;
docker run --net ghactions_mm-test appropriate/curl:latest sh -c "until curl --max-time 5 --output - http://mysql:3306; do echo waiting for mysql; sleep 5; done;"
docker run --net ghactions_mm-test appropriate/curl:latest sh -c "until curl --max-time 5 --output - http://elasticsearch:9200; do echo waiting for elasticsearch; sleep 5; done;"
- name: Initialize the database with the source DB dump
run: |
curl ${{ inputs.db-dump-url }} | zcat | docker exec -i ghactions_mysql_1 mysql -AN $MYSQL_CONN_ARGS
- name: Common preprocessing of the DB dump
run: |
cd server/scripts/esrupgrades
docker exec -i ghactions_mysql_1 mysql -AN $MYSQL_CONN_ARGS < $PREPROCESS_SCRIPT
- name: Pull EE image
run: |
docker pull $BUILD_IMAGE
- name: Run migration through server
run: |
mkdir -p client/plugins
cd server/build
# Run the server in the background to trigger the migrations
docker run --name mmserver \
--net ghactions_mm-test \
--ulimit nofile=8096:8096 \
--env-file=dotenv/test.env \
--env MM_SQLSETTINGS_DRIVERNAME="mysql" \
--env MM_SQLSETTINGS_DATASOURCE="mmuser:mostest@tcp(mysql:3306)/mattermost_test?charset=utf8mb4&multiStatements=true&maxAllowedPacket=4194304" \
-v ~/work/mattermost:/mm \
-w /mm \
$BUILD_IMAGE &
# In parallel, wait for the migrations to finish.
# To verify this, we check that the server has finished the startup job through the log line "Server is listening on"
until docker logs mmserver | grep "Server is listening on"; do\
echo "Waiting for migrations to finish..."; \
sleep 1; \
done;
# Make sure to stop the server. Also, redirect output to null;
# otherwise, the name of the container gets written to the console, which is weird
docker stop mmserver > /dev/null
- name: Cleanup DB
run: |
cd server/scripts/esrupgrades
docker exec -i ghactions_mysql_1 mysql -AN $MYSQL_CONN_ARGS < $CLEANUP_SCRIPT
- name: Dump upgraded database
run: |
# Use --skip-opt to have each INSERT into one line.
# Use --set-gtid-purged=OFF to suppress GTID-related statements.
docker exec -i ghactions_mysql_1 mysqldump \
--skip-opt --set-gtid-purged=OFF \
$MYSQL_CONN_ARGS > $DUMP_SERVER_NAME
- name: Cleanup dump and compress
run: |
# We skip the very last line, which simply contains the date of the dump
head -n -1 ${DUMP_SERVER_NAME} | gzip > ${DUMP_SERVER_NAME}.gz
- name: Upload dump
uses: actions/upload-artifact@v4
with:
name: upgraded-dump-server
path: ${{ env.DUMP_SERVER_NAME }}.gz
esr-upgrade-script:
runs-on: ubuntu-latest-8-cores
timeout-minutes: 30
steps:
- name: Checkout mattermost project
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Run docker compose
run: |
cd server/build
docker compose --no-ansi run --rm start_dependencies
cat ../tests/test-data.ldif | docker compose --no-ansi exec -T openldap bash -c 'ldapadd -x -D "cn=admin,dc=mm,dc=test,dc=com" -w mostest';
docker compose --no-ansi exec -T minio sh -c 'mkdir -p /data/mattermost-test';
docker compose --no-ansi ps
- name: Wait for docker compose
run: |
until docker network inspect ghactions_mm-test; do echo "Waiting for Docker Compose Network..."; sleep 1; done;
docker run --net ghactions_mm-test appropriate/curl:latest sh -c "until curl --max-time 5 --output - http://mysql:3306; do echo waiting for mysql; sleep 5; done;"
docker run --net ghactions_mm-test appropriate/curl:latest sh -c "until curl --max-time 5 --output - http://elasticsearch:9200; do echo waiting for elasticsearch; sleep 5; done;"
- name: Initialize the database with the source DB dump
run: |
curl ${{ inputs.db-dump-url }} | zcat | docker exec -i ghactions_mysql_1 mysql -AN $MYSQL_CONN_ARGS
- name: Preprocess the DB dump
run: |
cd server/scripts/esrupgrades
docker exec -i ghactions_mysql_1 mysql -AN $MYSQL_CONN_ARGS < $PREPROCESS_SCRIPT
- name: Run migration through script
run: |
cd server/scripts/esrupgrades
docker exec -i ghactions_mysql_1 mysql -AN $MYSQL_CONN_ARGS < $MIGRATION_SCRIPT
- name: Cleanup DB
run: |
cd server/scripts/esrupgrades
docker exec -i ghactions_mysql_1 mysql -AN $MYSQL_CONN_ARGS < $CLEANUP_SCRIPT
- name: Dump upgraded database
run: |
docker exec -i ghactions_mysql_1 mysqldump --skip-opt --set-gtid-purged=OFF $MYSQL_CONN_ARGS > $DUMP_SCRIPT_NAME
- name: Cleanup dump and compress
run: |
# We skip the very last line, which simply contains the date of the dump
head -n -1 ${DUMP_SCRIPT_NAME} | gzip > ${DUMP_SCRIPT_NAME}.gz
- name: Upload dump
uses: actions/upload-artifact@v4
with:
name: upgraded-dump-script
path: ${{ env.DUMP_SCRIPT_NAME }}.gz
esr-upgrade-diff:
runs-on: ubuntu-latest
needs:
- esr-upgrade-server
- esr-upgrade-script
steps:
- name: Retrieve dumps
uses: actions/download-artifact@v4
- name: Diff dumps
run: |
gzip -d upgraded-dump-server/${DUMP_SERVER_NAME}.gz
gzip -d upgraded-dump-script/${DUMP_SCRIPT_NAME}.gz
diff upgraded-dump-server/$DUMP_SERVER_NAME upgraded-dump-script/$DUMP_SCRIPT_NAME > $DIFF_NAME
- name: Upload diff
if: failure() # Upload the diff only if the previous step failed; i.e., if the diff is non-empty
uses: actions/upload-artifact@v4
with:
name: dumps-diff
path: ${{ env.DIFF_NAME }}