/
mysql.yaml
107 lines (97 loc) · 2.84 KB
/
mysql.yaml
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
# Copyright 2023 Google LLC
#
# 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.
apiVersion: v1
kind: ConfigMap
metadata:
name: chat-config
data:
chat.sql: |
USE chat;
CREATE TABLE IF NOT EXISTS threads (
thread INTEGER AUTO_INCREMENT PRIMARY KEY,
creator VARCHAR(256) NOT NULL
);
CREATE TABLE IF NOT EXISTS userthreads (
user VARCHAR(256) NOT NULL,
thread INTEGER NOT NULL,
CONSTRAINT uthread FOREIGN KEY(thread) REFERENCES threads(thread)
);
CREATE TABLE IF NOT EXISTS images (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
image BLOB NOT NULL
);
CREATE TABLE IF NOT EXISTS posts (
post INTEGER AUTO_INCREMENT PRIMARY KEY,
thread INTEGER NOT NULL,
creator VARCHAR(256) NOT NULL,
time INTEGER NOT NULL,
text TEXT NOT NULL,
imageid INTEGER,
CONSTRAINT pthread FOREIGN KEY (thread) REFERENCES threads(thread),
CONSTRAINT pimageid FOREIGN KEY (imageid) REFERENCES images(id)
);
CREATE INDEX thread ON threads (thread);
CREATE INDEX uthread ON userthreads (thread);
CREATE INDEX image ON images (id);
---
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: mysql
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: password
- name: MYSQL_DATABASE
value: chat
ports:
- containerPort: 3306
volumeMounts:
- name: config
# As described in https://hub.docker.com/_/mysql, the MySQL instance
# will automatically run all .sql files stored in
# /docker-entrypoint-initdb.d.
mountPath: /docker-entrypoint-initdb.d/chat.sql
subPath: chat.sql
lifecycle:
postStart:
exec:
# chat.sql is mounted as the root user, but the MySQL instance
# runs as the mysql user and needs access to this file.
command: ["/bin/sh", "chown", "mysql:mysql", "/docker-entrypoint-initdb.d/chat.sql"]
volumes:
- name: config
configMap:
name: chat-config