Skip to content

Commit c7b292c

Browse files
committed
Add Docker support with image build, CI workflow, and README updates
1 parent 85bc81e commit c7b292c

4 files changed

Lines changed: 164 additions & 0 deletions

File tree

.dockerignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Mirrors .gitignore so build artifacts and IDE/VCS files are NOT copied into the image.
2+
# The image rebuilds target/ and re-populates the Maven repo itself, then keeps them.
3+
.git
4+
.gitignore
5+
6+
# Build output
7+
**/target/
8+
target/
9+
build/
10+
out/
11+
12+
# IDE
13+
.idea/
14+
.idea_modules/
15+
*.iws
16+
*.iml
17+
.classpath
18+
.project
19+
atlassian-ide-plugin.xml
20+
21+
# Maven / release scratch files
22+
.mvn/timing.properties
23+
.mvn/wrapper/maven-wrapper.jar
24+
dependency-reduced-pom.xml
25+
pom.xml.next
26+
pom.xml.releaseBackup
27+
pom.xml.tag
28+
pom.xml.versionsBackup
29+
release.properties
30+
buildNumber.properties
31+
32+
# CMake
33+
cmake-build-*/
34+
35+
# Crashlytics / Fabric
36+
com_crashlytics_export_strings.xml
37+
crashlytics-build.properties
38+
crashlytics.properties
39+
fabric.properties
40+
41+
# Docker scratch
42+
Dockerfile
43+
.dockerignore

.github/workflows/build.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: build
2+
3+
# Builds the project inside the Docker image (downloading all Maven dependencies and
4+
# producing the module jars), then publishes the image to GitHub Container Registry.
5+
on:
6+
push:
7+
branches: [ main, master ]
8+
tags: [ 'v*' ]
9+
pull_request:
10+
workflow_dispatch:
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: ${{ github.repository }}
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
packages: write
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
29+
# Push everywhere except on pull requests (PRs from forks can't access GHCR).
30+
- name: Log in to GitHub Container Registry
31+
if: github.event_name != 'pull_request'
32+
uses: docker/login-action@v3
33+
with:
34+
registry: ${{ env.REGISTRY }}
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Docker metadata
39+
id: meta
40+
uses: docker/metadata-action@v5
41+
with:
42+
# metadata-action lowercases the image name, so mixed-case owners are fine.
43+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
44+
tags: |
45+
type=ref,event=branch
46+
type=ref,event=tag
47+
type=sha
48+
type=raw,value=latest,enable={{is_default_branch}}
49+
50+
# The Dockerfile runs `mvn install` (install the deps and build in the image build),
51+
# keeping the downloaded deps, built jars and source inside the published image.
52+
- name: Build and push image
53+
uses: docker/build-push-action@v6
54+
with:
55+
context: .
56+
push: ${{ github.event_name != 'pull_request' }}
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}
59+
cache-from: type=gha
60+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Builds the whole project and KEEPS everything in the final image:
2+
# - every downloaded Maven dependency -> /root/.m2/repository
3+
# - every built module jar / build artifact -> /workspace/spark-test/**/target
4+
# - the project source code -> /workspace/spark-test
5+
#
6+
# The source is copied as-is except for the files excluded by .dockerignore
7+
# (which mirrors .gitignore), so generated/IDE/VCS files are not brought in.
8+
#
9+
# Tests are NOT run during the image build: the scenario needs a Docker daemon
10+
# (Testcontainers), which is not available inside an image build. Dependencies and
11+
# jars are still fully resolved and produced.
12+
FROM maven:3.9-eclipse-temurin-17
13+
14+
# Optional proxy support for local builds behind an HTTP proxy (empty in CI).
15+
# Example: docker build --build-arg HTTPS_PROXY=http://host.docker.internal:10809 .
16+
ARG HTTP_PROXY=""
17+
ARG HTTPS_PROXY=""
18+
ARG NO_PROXY=""
19+
ENV HTTP_PROXY=${HTTP_PROXY} HTTPS_PROXY=${HTTPS_PROXY} NO_PROXY=${NO_PROXY} \
20+
http_proxy=${HTTP_PROXY} https_proxy=${HTTPS_PROXY} no_proxy=${NO_PROXY}
21+
22+
WORKDIR /workspace/spark-test
23+
24+
# Copy the project source (ignored files are filtered out by .dockerignore).
25+
COPY . .
26+
27+
# Archive the (gitignore-filtered) source into the image as a tarball, before building
28+
# so it holds pure source with no target/ build output.
29+
RUN tar --exclude='*/target' -czf /workspace/spark-test-src.tgz -C /workspace spark-test
30+
31+
# Install all dependencies and build the module jars; keep the local repo + target dirs.
32+
# Do NOT use a cache mount here on purpose: the downloaded deps must persist in the image.
33+
RUN mvn -B -e install -DskipTests
34+
35+
CMD ["bash"]

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,29 @@ mvn -pl spark-cloudera test
9999
# or both
100100
mvn test
101101
```
102+
103+
## Docker image
104+
105+
The [`Dockerfile`](Dockerfile) builds the whole project inside the image and **keeps everything**:
106+
all downloaded Maven dependencies (`/root/.m2/repository`), every built module jar
107+
(`**/target/*.jar`), the project source (`/workspace/spark-test`), and a source tarball
108+
(`/workspace/spark-test-src.tgz`, captured before the build so it is pure source with no
109+
`target/`). The source is copied except for the files excluded by [`.dockerignore`](.dockerignore),
110+
which mirrors `.gitignore` (so `target/`, `.idea/`, `.git`, etc. are not brought in). Tests are
111+
skipped during the image build because Testcontainers needs a Docker daemon that isn't available
112+
there.
113+
114+
```bash
115+
docker build -t spark-test .
116+
117+
# Behind an HTTP proxy (e.g. local dev), pass it through:
118+
docker build --build-arg HTTPS_PROXY=http://host.docker.internal:10809 -t spark-test .
119+
```
120+
121+
## CI / GitHub Container Registry
122+
123+
[`.github/workflows/build.yml`](.github/workflows/build.yml) builds that image (installing the deps
124+
and building the jars in the image build) and publishes it to **GitHub Container Registry**
125+
(`ghcr.io/<owner>/spark-test`) on pushes to the default branch and on `v*` tags. It needs no extra
126+
secrets — it authenticates with the built-in `GITHUB_TOKEN` (`packages: write`). Pull requests build
127+
the image but do not push.

0 commit comments

Comments
 (0)