Skip to content

Commit 4bef9c8

Browse files
PS4M. Add workflow to build mongot image on PRs
1 parent 12079c4 commit 4bef9c8

4 files changed

Lines changed: 269 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: dev-docker-image-cleanup
2+
3+
# When a PR is closed (merged or not), delete the per-PR dev image tag
4+
# (perconalab/percona-search-mongodb:pr-<number>) from Docker Hub so stale
5+
# dev tags don't accumulate. GitHub artifacts are left to expire on their own
6+
# retention window.
7+
8+
on:
9+
pull_request:
10+
types: [closed]
11+
branches:
12+
- main
13+
14+
env:
15+
REPO: perconalab/percona-search-mongodb
16+
17+
jobs:
18+
delete-tag:
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 10
21+
env:
22+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
23+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
24+
steps:
25+
- name: Delete pr-<number> tag from Docker Hub
26+
if: env.DOCKERHUB_TOKEN != ''
27+
run: |
28+
set -e
29+
TAG="pr-${{ github.event.pull_request.number }}"
30+
echo "Deleting ${REPO}:${TAG}"
31+
32+
JWT=$(curl -sS -H "Content-Type: application/json" \
33+
-X POST \
34+
-d "{\"username\": \"${DOCKERHUB_USERNAME}\", \"password\": \"${DOCKERHUB_TOKEN}\"}" \
35+
https://hub.docker.com/v2/users/login/ | jq -r .token)
36+
37+
if [ -z "${JWT}" ] || [ "${JWT}" = "null" ]; then
38+
echo "Failed to obtain Docker Hub auth token" >&2
39+
exit 1
40+
fi
41+
42+
HTTP_CODE=$(curl -sS -o /dev/null -w "%{http_code}" \
43+
-X DELETE \
44+
-H "Authorization: JWT ${JWT}" \
45+
"https://hub.docker.com/v2/repositories/${REPO}/tags/${TAG}/")
46+
47+
case "${HTTP_CODE}" in
48+
204) echo "Deleted ${REPO}:${TAG}" ;;
49+
404) echo "Tag ${REPO}:${TAG} not found (already gone or never pushed); nothing to do" ;;
50+
*) echo "Unexpected response deleting tag: HTTP ${HTTP_CODE}" >&2; exit 1 ;;
51+
esac
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: dev-docker-image
2+
3+
# Builds mongot from source on every PR, packages it into docker image and:
4+
# * ALWAYS uploads the image as a GitHub artifact (docker save tarball)
5+
# * ADDITIONALLY pushes to perconalab/percona-search-mongodb:pr-<number>
6+
# when Docker Hub credentials are available
7+
# The pr-<number> tag is removed when the PR closes (see dev-docker-image-cleanup.yml).
8+
9+
on:
10+
workflow_dispatch:
11+
12+
pull_request:
13+
types: [opened, reopened, synchronize, ready_for_review]
14+
branches:
15+
- main
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: true
20+
21+
env:
22+
IMAGE: perconalab/percona-search-mongodb
23+
PLATFORM: linux_x86_64
24+
25+
jobs:
26+
build:
27+
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
28+
runs-on: ubuntu-latest
29+
timeout-minutes: 180
30+
permissions:
31+
contents: read
32+
env:
33+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
34+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
35+
steps:
36+
- name: Cleanup unnecessary software
37+
run: |
38+
df -h
39+
sudo rm -rf /usr/share/dotnet
40+
sudo rm -rf /usr/local/lib/android
41+
sudo rm -rf /opt/ghc
42+
sudo rm -rf /opt/hostedtoolcache/CodeQL
43+
df -h
44+
45+
- name: Checkout
46+
uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Compute image tag
51+
id: meta
52+
run: |
53+
if [ "${{ github.event_name }}" = "pull_request" ]; then
54+
TAG="pr-${{ github.event.pull_request.number }}"
55+
else
56+
TAG="dev-${GITHUB_SHA::8}"
57+
fi
58+
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
59+
echo "Image will be tagged: ${IMAGE}:${TAG}"
60+
61+
- name: Build mongot community bundle
62+
run: |
63+
./scripts/tools/bazelisk/run.sh build \
64+
--platforms=//bazel/platforms:${PLATFORM} \
65+
--//bazel/config:version=${{ steps.meta.outputs.tag }} \
66+
--embed_label=${{ steps.meta.outputs.tag }} \
67+
//deploy:mongot-community
68+
69+
- name: Assemble Docker build context
70+
run: |
71+
mkdir -p docker-context
72+
cp -L bazel-bin/deploy/mongot-community.tgz docker-context/mongot-community.tgz
73+
cp percona-packaging/docker/Dockerfile docker-context/Dockerfile
74+
cp percona-packaging/docker/mongot-entry.sh docker-context/mongot-entry.sh
75+
cp percona-packaging/conf/mongot.yml docker-context/mongot.yml
76+
ls -l docker-context
77+
78+
- name: Set up Docker Buildx
79+
uses: docker/setup-buildx-action@v3
80+
81+
- name: Build image
82+
run: |
83+
docker build docker-context \
84+
-t "${IMAGE}:${{ steps.meta.outputs.tag }}"
85+
86+
- name: Save image as artifact tarball
87+
run: |
88+
docker save "${IMAGE}:${{ steps.meta.outputs.tag }}" \
89+
| gzip > percona-search-mongodb-${{ steps.meta.outputs.tag }}.tar.gz
90+
ls -lh percona-search-mongodb-${{ steps.meta.outputs.tag }}.tar.gz
91+
92+
- name: Upload image artifact
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: percona-search-mongodb-${{ steps.meta.outputs.tag }}
96+
path: percona-search-mongodb-${{ steps.meta.outputs.tag }}.tar.gz
97+
if-no-files-found: error
98+
retention-days: 7
99+
100+
# The steps below run only when Docker Hub credentials are present.
101+
# Fork PRs never receive secrets, so these steps are skipped automatically
102+
- name: Log in to Docker Hub
103+
if: env.DOCKERHUB_TOKEN != ''
104+
uses: docker/login-action@v3
105+
with:
106+
username: ${{ secrets.DOCKERHUB_USERNAME }}
107+
password: ${{ secrets.DOCKERHUB_TOKEN }}
108+
109+
- name: Push image to perconalab
110+
if: env.DOCKERHUB_TOKEN != ''
111+
run: |
112+
docker push "${IMAGE}:${{ steps.meta.outputs.tag }}"
113+
echo "Pushed ${IMAGE}:${{ steps.meta.outputs.tag }}"
114+
115+
- name: Summary
116+
if: always()
117+
run: |
118+
{
119+
echo "### mongot dev image"
120+
echo ""
121+
echo "- Tag: \`${IMAGE}:${{ steps.meta.outputs.tag }}\`"
122+
echo "- Artifact: \`percona-search-mongodb-${{ steps.meta.outputs.tag }}\` (load with \`docker load < *.tar.gz\`)"
123+
if [ -n "${DOCKERHUB_TOKEN}" ]; then
124+
echo "- Pushed to Docker Hub: yes (\`docker pull ${IMAGE}:${{ steps.meta.outputs.tag }}\`)"
125+
else
126+
echo "- Pushed to Docker Hub: no (credentials unavailable, e.g. fork PR)"
127+
fi
128+
} >> "$GITHUB_STEP_SUMMARY"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
FROM redhat/ubi9-minimal
2+
3+
# Dev image: mongot (Percona Search for MongoDB) built from source in this repo
4+
LABEL name="Percona Search for MongoDB (dev)" \
5+
vendor="Percona" \
6+
summary="mongot built from percona-mongot source" \
7+
description="Development build of Percona Search for MongoDB (mongot). Built directly \
8+
from source instead of the published package. Not for production use." \
9+
org.opencontainers.image.title="Percona Search for MongoDB (dev)" \
10+
org.opencontainers.image.vendor="Percona" \
11+
org.opencontainers.image.source="https://github.com/percona/percona-mongot"
12+
13+
ARG BUNDLE=mongot-community.tgz
14+
ARG INSTALL_DIR=/usr/lib/percona-search-mongodb
15+
16+
RUN set -ex; \
17+
microdnf -y update; \
18+
microdnf -y install \
19+
tar \
20+
gzip \
21+
jq \
22+
oniguruma \
23+
shadow-utils \
24+
util-linux \
25+
vim-minimal; \
26+
microdnf clean all; \
27+
rm -rf /var/cache/dnf /var/cache/yum
28+
29+
COPY ${BUNDLE} /tmp/mongot-community.tgz
30+
RUN set -ex; \
31+
mkdir -p "${INSTALL_DIR}"; \
32+
tar -xzf /tmp/mongot-community.tgz \
33+
-C "${INSTALL_DIR}" --strip-components=1; \
34+
rm -f /tmp/mongot-community.tgz; \
35+
chmod +x "${INSTALL_DIR}/mongot"
36+
37+
RUN set -ex; \
38+
printf '#!/bin/sh\nexec %s/mongot "$@"\n' "${INSTALL_DIR}" > /usr/bin/mongot; \
39+
chmod +x /usr/bin/mongot
40+
41+
COPY mongot.yml /etc/mongot/mongot.yml
42+
43+
RUN set -ex; \
44+
useradd -u 1001 -r -g 0 -m -s /sbin/nologin \
45+
-c "Default Application User" mongodb; \
46+
mkdir -p /var/lib/mongot /var/log/mongot /etc/mongot/secrets; \
47+
chown -R 1001:0 "${INSTALL_DIR}" \
48+
/var/lib/mongot /var/log/mongot /etc/mongot; \
49+
chmod -R g+rwX "${INSTALL_DIR}" \
50+
/var/lib/mongot /var/log/mongot; \
51+
chmod -R g+rX /etc/mongot
52+
53+
COPY mongot-entry.sh /entrypoint.sh
54+
RUN chmod +x /entrypoint.sh
55+
56+
USER 1001
57+
58+
VOLUME ["/var/lib/mongot"]
59+
60+
# 27028 grpc query server, 9946 metrics, 8080 health endpoint
61+
EXPOSE 27028 9946 8080
62+
63+
ENTRYPOINT ["/entrypoint.sh"]
64+
CMD ["mongot", "--config", "/etc/mongot/mongot.yml"]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
#
3+
# Entry point for the Percona Search for MongoDB (mongot) dev image.
4+
#
5+
# This lets operators pass mongot options as arguments to the container, e.g.:
6+
#
7+
# docker run ... percona-search-mongodb --config /path/to/mongot.yml
8+
#
9+
# while a plain `docker run` still starts mongot with the bundled default
10+
# config supplied via CMD. Any other command (e.g. `bash`) is execed as-is
11+
# so the image stays debuggable.
12+
set -e
13+
14+
# First argument is a flag -> the operator is passing mongot options; prepend
15+
# the binary so they don't have to restate it.
16+
if [ "${1:0:1}" = '-' ]; then
17+
set -- mongot "$@"
18+
fi
19+
20+
# Normalize the bare `mongot` command to its absolute path.
21+
if [ "$1" = 'mongot' ]; then
22+
shift
23+
set -- /usr/bin/mongot "$@"
24+
fi
25+
26+
exec "$@"

0 commit comments

Comments
 (0)