Skip to content

Commit 8d095e1

Browse files
authored
perf(docker): improve all images build cache efficiency (#3025)
- Fix .gitattribut -> .gitattributes typo in .dockerignore - Fix **/*.tar.gz* -> **/*.tar.gz (remove unintended trailing wildcard) - Remove **/target/dist/ (redundant, already covered by **/target/) - Restore cron to apt-get install in all 4 Dockerfiles to keep the existing start-hugegraph.sh -m true monitor path working
1 parent 66e5339 commit 8d095e1

6 files changed

Lines changed: 149 additions & 47 deletions

File tree

.dockerignore

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
# IMPORTANT: .dockerignore does NOT inherit .gitignore — patterns must be restated.
19+
20+
# Build output
21+
**/target/
22+
23+
# Pre-extracted release dirs / archives
24+
apache-hugegraph-*/
25+
**/*.tar
26+
**/*.tar.gz
27+
**/*.zip
28+
**/*.war
29+
30+
# IDE / OS
31+
.idea/
32+
.vscode/
33+
**/*.iml
34+
**/*.iws
35+
**/.DS_Store
36+
37+
# Build / runtime artifacts
38+
**/logs/
39+
**/*.log
40+
**/*.class
41+
**/gen-java/
42+
**/upload-files/
43+
**/build/
44+
**/node_modules/
45+
46+
# Env files
47+
.env.local
48+
.env.*.local
49+
50+
# Git internals
51+
.git
52+
.gitignore
53+
.gitattributes
54+
.github
55+
56+
# Compose / docs not needed in build context
57+
**/docker-compose*.yml
58+
**/docker-compose*.yaml
59+
**/*.md
60+
docs/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
name: "Docker Build CI"
19+
20+
on:
21+
push:
22+
branches:
23+
- master
24+
- 'release-*'
25+
pull_request:
26+
paths:
27+
- '**/Dockerfile*'
28+
- '.dockerignore'
29+
30+
jobs:
31+
docker-build:
32+
runs-on: ubuntu-24.04
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
dockerfile:
37+
- hugegraph-pd/Dockerfile
38+
- hugegraph-store/Dockerfile
39+
- hugegraph-server/Dockerfile
40+
- hugegraph-server/Dockerfile-hstore
41+
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v4
45+
46+
- name: Build ${{ matrix.dockerfile }}
47+
run: |
48+
docker build -f ${{ matrix.dockerfile }} .

hugegraph-pd/Dockerfile

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
#
23
# Licensed to the Apache Software Foundation (ASF) under one or more
34
# contributor license agreements. See the NOTICE file distributed with
@@ -19,12 +20,15 @@
1920
# 1st stage: build source code
2021
FROM maven:3.9.0-eclipse-temurin-11 AS build
2122

22-
COPY . /pkg
2323
WORKDIR /pkg
24+
25+
COPY . .
26+
2427
ARG MAVEN_ARGS
2528

26-
RUN mvn package $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true && pwd && ls -l && rm \
27-
./hugegraph-server/*.tar.gz && rm ./hugegraph-pd/*.tar.gz && rm ./hugegraph-store/*.tar.gz
29+
RUN --mount=type=cache,target=/root/.m2 \
30+
mvn package $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \
31+
&& rm ./hugegraph-server/*.tar.gz ./hugegraph-pd/*.tar.gz ./hugegraph-store/*.tar.gz
2832

2933
# 2nd stage: runtime env
3034
# Note: ZGC (The Z Garbage Collector) is only supported on ARM-Mac with java > 13
@@ -38,14 +42,10 @@ ENV JAVA_OPTS="-XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport -XX:Max
3842
HUGEGRAPH_HOME="hugegraph-pd" \
3943
STDOUT_MODE="true"
4044

41-
#COPY . /hugegraph/hugegraph-pd
4245
WORKDIR /hugegraph-pd/
4346

44-
# 1. Install environment and init HugeGraph Sever
45-
RUN set -x \
46-
&& rm /var/lib/dpkg/info/libc-bin.* \
47-
&& apt-get -q clean \
48-
&& apt-get -q update \
47+
# 1. Install runtime dependencies
48+
RUN apt-get -q update \
4949
&& apt-get -q install -y --no-install-recommends --no-install-suggests \
5050
dumb-init \
5151
procps \
@@ -54,9 +54,7 @@ RUN set -x \
5454
vim \
5555
cron \
5656
&& apt-get clean \
57-
&& rm -rf /var/lib/apt/lists/* \
58-
&& service cron start \
59-
&& pwd && cd /hugegraph-pd/
57+
&& rm -rf /var/lib/apt/lists/*
6058

6159
# 2. Init docker script
6260
COPY hugegraph-pd/hg-pd-dist/docker/docker-entrypoint.sh .

hugegraph-server/Dockerfile

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
#
23
# Licensed to the Apache Software Foundation (ASF) under one or more
34
# contributor license agreements. See the NOTICE file distributed with
@@ -19,15 +20,18 @@
1920
# 1st stage: build source code
2021
FROM maven:3.9.0-eclipse-temurin-11 AS build
2122

22-
COPY . /pkg
2323
WORKDIR /pkg
24+
25+
COPY . .
26+
2427
ARG MAVEN_ARGS
2528

26-
RUN mvn package $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true && pwd && ls -l && rm \
27-
./hugegraph-server/*.tar.gz && rm ./hugegraph-pd/*.tar.gz && rm ./hugegraph-store/*.tar.gz
29+
RUN --mount=type=cache,target=/root/.m2 \
30+
mvn package $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \
31+
&& rm ./hugegraph-server/*.tar.gz ./hugegraph-pd/*.tar.gz ./hugegraph-store/*.tar.gz
2832

2933
# 2nd stage: runtime env
30-
# Note: ZGC (The Z Garbage Collector) is only supported on ARM-Mac with java > 13
34+
# Note: ZGC (The Z Garbage Collector) is only supported on ARM-Mac with java > 13
3135
FROM eclipse-temurin:11-jre-jammy
3236

3337
COPY --from=build /pkg/hugegraph-server/apache-hugegraph-server-*/ /hugegraph-server/
@@ -39,14 +43,10 @@ ENV JAVA_OPTS="-XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport -XX:Max
3943
HUGEGRAPH_HOME="hugegraph-server" \
4044
STDOUT_MODE="true"
4145

42-
#COPY . /hugegraph/hugegraph-server
4346
WORKDIR /hugegraph-server/
4447

45-
# 1. Install environment and init HugeGraph Sever
46-
RUN set -x \
47-
&& rm /var/lib/dpkg/info/libc-bin.* \
48-
&& apt-get -q clean \
49-
&& apt-get -q update \
48+
# 1. Install runtime dependencies and configure server
49+
RUN apt-get -q update \
5050
&& apt-get -q install -y --no-install-recommends --no-install-suggests \
5151
dumb-init \
5252
procps \
@@ -56,8 +56,6 @@ RUN set -x \
5656
cron \
5757
&& apt-get clean \
5858
&& rm -rf /var/lib/apt/lists/* \
59-
&& service cron start \
60-
&& pwd && cd /hugegraph-server/ \
6159
&& sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g" ./conf/rest-server.properties
6260

6361
# 2. Init docker script

hugegraph-server/Dockerfile-hstore

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
#
23
# Licensed to the Apache Software Foundation (ASF) under one or more
34
# contributor license agreements. See the NOTICE file distributed with
@@ -15,19 +16,22 @@
1516
# limitations under the License.
1617
#
1718

18-
# Dockerfile for HugeGraph Server
19+
# Dockerfile for HugeGraph Server (hstore backend)
1920
# 1st stage: build source code
2021
FROM maven:3.9.0-eclipse-temurin-11 AS build
2122

22-
COPY . /pkg
2323
WORKDIR /pkg
24+
25+
COPY . .
26+
2427
ARG MAVEN_ARGS
2528

26-
RUN mvn package $MAVEN_ARGS -e -B -ntp -DskipTests -Dmaven.javadoc.skip=true && pwd && ls -l && rm \
27-
./hugegraph-server/*.tar.gz && rm ./hugegraph-pd/*.tar.gz && rm ./hugegraph-store/*.tar.gz
29+
RUN --mount=type=cache,target=/root/.m2 \
30+
mvn package $MAVEN_ARGS -e -B -ntp -DskipTests -Dmaven.javadoc.skip=true \
31+
&& rm ./hugegraph-server/*.tar.gz ./hugegraph-pd/*.tar.gz ./hugegraph-store/*.tar.gz
2832

2933
# 2nd stage: runtime env
30-
# Note: ZGC (The Z Garbage Collector) is only supported on ARM-Mac with java > 13
34+
# Note: ZGC (The Z Garbage Collector) is only supported on ARM-Mac with java > 13
3135
FROM eclipse-temurin:11-jre-jammy
3236

3337
COPY --from=build /pkg/hugegraph-server/apache-hugegraph-server-*/ /hugegraph-server/
@@ -41,12 +45,10 @@ LABEL maintainer="HugeGraph Docker Maintainers <dev@hugegraph.apache.org>"
4145
ENV JAVA_OPTS="-XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport -XX:MaxRAMPercentage=50 -XshowSettings:vm" \
4246
HUGEGRAPH_HOME="hugegraph-server"
4347

44-
#COPY . /hugegraph/hugegraph-server
4548
WORKDIR /hugegraph-server/
4649

47-
# 1. Install environment and init HugeGraph Sever
48-
RUN set -x \
49-
&& apt-get -q update \
50+
# 1. Install runtime dependencies and configure server
51+
RUN apt-get -q update \
5052
&& apt-get -q install -y --no-install-recommends --no-install-suggests \
5153
dumb-init \
5254
procps \
@@ -56,8 +58,6 @@ RUN set -x \
5658
cron \
5759
&& apt-get clean \
5860
&& rm -rf /var/lib/apt/lists/* \
59-
&& service cron start \
60-
&& pwd && cd /hugegraph-server/ \
6161
&& sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g" ./conf/rest-server.properties
6262

6363
# 2. Init docker script

hugegraph-store/Dockerfile

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# syntax=docker/dockerfile:1
12
#
23
# Licensed to the Apache Software Foundation (ASF) under one or more
34
# contributor license agreements. See the NOTICE file distributed with
@@ -19,12 +20,15 @@
1920
# 1st stage: build source code
2021
FROM maven:3.9.0-eclipse-temurin-11 AS build
2122

22-
COPY . /pkg
2323
WORKDIR /pkg
24+
25+
COPY . .
26+
2427
ARG MAVEN_ARGS
2528

26-
RUN mvn package $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true && pwd && ls -l && rm \
27-
./hugegraph-server/*.tar.gz && rm ./hugegraph-pd/*.tar.gz && rm ./hugegraph-store/*.tar.gz
29+
RUN --mount=type=cache,target=/root/.m2 \
30+
mvn package $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \
31+
&& rm ./hugegraph-server/*.tar.gz ./hugegraph-pd/*.tar.gz ./hugegraph-store/*.tar.gz
2832

2933
# 2nd stage: runtime env
3034
# Note: ZGC (The Z Garbage Collector) is only supported on ARM-Mac with java > 13
@@ -38,14 +42,10 @@ ENV JAVA_OPTS="-XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport -XX:Max
3842
HUGEGRAPH_HOME="hugegraph-store" \
3943
STDOUT_MODE="true"
4044

41-
#COPY . /hugegraph/hugegraph-store
4245
WORKDIR /hugegraph-store/
4346

44-
# 1. Install environment and init HugeGraph Sever
45-
RUN set -x \
46-
&& rm /var/lib/dpkg/info/libc-bin.* \
47-
&& apt-get -q clean \
48-
&& apt-get -q update \
47+
# 1. Install runtime dependencies
48+
RUN apt-get -q update \
4949
&& apt-get -q install -y --no-install-recommends --no-install-suggests \
5050
dumb-init \
5151
procps \
@@ -54,9 +54,7 @@ RUN set -x \
5454
vim \
5555
cron \
5656
&& apt-get clean \
57-
&& rm -rf /var/lib/apt/lists/* \
58-
&& service cron start \
59-
&& pwd && cd /hugegraph-store/
57+
&& rm -rf /var/lib/apt/lists/*
6058

6159
# 2. Init docker script
6260
COPY hugegraph-store/hg-store-dist/docker/docker-entrypoint.sh .

0 commit comments

Comments
 (0)