-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
40 lines (29 loc) · 1.35 KB
/
Dockerfile
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
FROM mysql:latest as dumper
WORKDIR /root
# Install dependencies
RUN microdnf install -y unzip less
# Install awscli
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip "awscliv2.zip" && ./aws/install
# Make the sql dump
RUN --mount=type=secret,id=aws,target=/root/.aws/credentials \
--mount=type=secret,id=db-host,env=DB_HOST \
--mount=type=secret,id=db-password,env=DB_PASSWORD \
--mount=type=secret,id=db-username,env=DB_USERNAME \
--mount=type=secret,id=db-name,env=DB_NAME \
echo "Dumping database $RDS_DB_NAME..." && \
mysqldump --single-transaction --set-gtid-purged=OFF --databases -h "$DB_HOST" -u "$DB_USERNAME" -p"$DB_PASSWORD" "$DB_NAME" > rds_dump.sql
# Copy the dump file to a temporary location
RUN cp rds_dump.sql /tmp/rds_dump.sql
# Stage 2: Final stage
FROM mysql:latest
WORKDIR /root
# Copy the dump file from the dumper stage
COPY --from=dumper /tmp/rds_dump.sql /docker-entrypoint-initdb.d/rds_dump.sql
# Make the password accessible to both build and runtime
ARG MYSQL_ROOT_PASSWORD
ENV MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
# Enable general logs
RUN sed -i '/\[mysqld\]/a general_log = ON\ngeneral_log_file = /var/lib/mysql/general.log' /etc/my.cnf
# To follow the logs (optional)
RUN echo "tail -f /var/lib/mysql/general.log" > /root/follow-logs.sh
RUN chmod +x /root/follow-logs.sh