-
Notifications
You must be signed in to change notification settings - Fork 0
/
dockerfile.memgraph
90 lines (73 loc) · 3.84 KB
/
dockerfile.memgraph
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
FROM node:22.3.0-alpine3.20 AS node
##################################### Neo4j Server #####################################
FROM memgraph/memgraph:latest as memgraph
###################################### Base image ######################################
FROM docker:26.1.4-dind-alpine3.20 as base
COPY --from=memgraph /usr/lib/memgraph/memgraph /usr/lib/memgraph/memgraph
##################################### Google Cloud #####################################
ARG CLOUD_SDK_VERSION=481.0.0
ENV CLOUD_SDK_VERSION=$CLOUD_SDK_VERSION
ENV PATH /google-cloud-sdk/bin:$PATH
RUN if [ `uname -m` = 'x86_64' ]; then echo -n "x86_64" > /tmp/arch; else echo -n "arm" > /tmp/arch; fi;
RUN ARCH=`cat /tmp/arch` && apk --no-cache add \
curl \
python3 \
py3-crcmod \
py3-openssl \
bash \
libc6-compat \
openssh-client \
git \
gnupg \
&& curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-${ARCH}.tar.gz && \
tar xzf google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-${ARCH}.tar.gz && \
rm google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-${ARCH}.tar.gz && \
gcloud config set core/disable_usage_reporting true && \
gcloud config set component_manager/disable_update_check true && \
gcloud config set metrics/environment github_docker_image && \
gcloud --version
RUN git config --system credential.'https://source.developers.google.com'.helper gcloud.sh
###################################### Add node ######################################
COPY --from=node /usr/lib /usr/lib
COPY --from=node /usr/local/lib /usr/local/lib
COPY --from=node /usr/local/include /usr/local/include
COPY --from=node /usr/local/bin /usr/local/bin
####################################### Script #######################################
WORKDIR /project
COPY . .
WORKDIR /project/sql-dump-to-memgraph
RUN npm i
WORKDIR /project/
CMD \
cd /project/sql-dump-to-memgraph &&\
# Copy the GCP credential to GCP.json file from the ENV
echo $GCP_JSON > GCP.json &&\
# Connect to Google Cloud
gcloud auth activate-service-account --key-file=GCP.json &&\
# Start Neo4j in background
/usr/lib/memgraph/memgraph &\
# Build and run the dump parser with Node js
npm start &&\
# Login to docker hub
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD &&\
# cd to start building a image for cloud run
cd / &&\
# Build the image for the current lang
docker build -f /project/serverless-docker-memgraph/dockerfile.memgraph / --build-arg wiki_lang=${WIKI_LANG} -t sacramentix1225/${WIKI_LANG}wiki-memgraph &&\
# Push it to docker hub
docker push sacramentix1225/${WIKI_LANG}wiki-memgraph &&\
# Configure to push to GCR hub too
gcloud auth configure-docker europe-west9-docker.pkg.dev --quiet &&\
# Configure to push to GCR hub too
docker tag sacramentix1225/${WIKI_LANG}wiki-memgraph europe-west9-docker.pkg.dev/sixdegreesofwikiadventure/wiki-graph/${WIKI_LANG}wiki-memgraph &&\
# Push to GCR.io
docker push europe-west9-docker.pkg.dev/sixdegreesofwikiadventure/wiki-graph/${WIKI_LANG}wiki-memgraph &&\
# Create a new Google Cloud Run
gcloud run deploy ${WIKI_LANG}wiki-graph-serverless --image=europe-west9-docker.pkg.dev/sixdegreesofwikiadventure/wiki-graph/${WIKI_LANG}wiki-memgraph:latest \
--cpu=8 --max-instances=5 --memory=32Gi --port=8080 --allow-unauthenticated \
--execution-environment=gen2 \
--region=europe-west9 --project=sixdegreesofwikiadventure &&\
# Delete the Instance running this script
export INSTANCE_NAME=$(curl -X GET http://metadata.google.internal/computeMetadata/v1/instance/name -H 'Metadata-Flavor: Google') &&\
export INSTANCE_ZONE=$(curl -X GET http://metadata.google.internal/computeMetadata/v1/instance/zone -H 'Metadata-Flavor: Google') &&\
gcloud --quiet compute instances delete $INSTANCE_NAME --zone=$INSTANCE_ZONE