forked from GoogleCloudPlatform/spanner-migration-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
65 lines (51 loc) · 2.89 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright 2022 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.
## Note - This file is not used in the current build and release process
# syntax=docker/dockerfile:1
############################# BUILD ###############################
# This stage builds the Spanner migration tool binary using its source code.
# Add golang as the base image for the build stage.
FROM golang:1.23.1 AS build
# Set the default work directory as “/spanner_migration_tool_bin” in the container.
WORKDIR /spanner_migration_tool_bin
# Copy Spanner migration tool’s source code into the working directory.
COPY . ./
# Download Spanner migration tool’s dependencies mentioned in the go.mod file.
RUN go mod tidy
# Compile the source code and store the binary in the work directory /spanner_migration_tool_bin.
RUN make build-static
########################### RELEASE ###############################
# This stage consists of the GCloud SDK and the Spanner migration tool binary.
# Add the Ubuntu base image from the Google Container Registry.
FROM gcr.io/cloud-marketplace/google/ubuntu1804@sha256:d9fe979ab72ff02f5b5d95c59cda6681aa73039fbf9b46596935267cf26c692e
# Set the default working directory.
# This directory binds with the host directory that is to store the output files generated by Spanner migration tool.
WORKDIR /spanner_migration_tool/spanner_migration_tool_output
# Create directory to store the Spanner migration tool binary.
RUN mkdir /spanner_migration_tool/bin
# Create directory to store the dump files. This directory binds with the host directory that contains the dump files of the source database.
RUN mkdir /spanner_migration_tool/source_dump
# Copy the spanner-migration-tool binary from the build stage's spanner_migration_tool_bin directory to the release stage's spanner_migration_tool/bin directory.
COPY --from=build /spanner_migration_tool_bin/spanner-migration-tool /spanner_migration_tool/bin
# Add Python3 to support GCloud SDK.
RUN apt-get update
RUN apt-get install -y python3.10
# Download the gcloud package.
RUN curl https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-391.0.0-linux-x86_64.tar.gz > /tmp/google-cloud-sdk.tar.gz
# Install the GCloud package.
RUN mkdir -p /usr/local/gcloud \
&& tar -C /usr/local/gcloud -xf /tmp/google-cloud-sdk.tar.gz \
&& /usr/local/gcloud/google-cloud-sdk/install.sh
# Add gcloud to $PATH.
ENV PATH $PATH:/usr/local/gcloud/google-cloud-sdk/bin