Skip to content

Commit ffa7a6a

Browse files
Add mongodb
1 parent 7f0371b commit ffa7a6a

File tree

6 files changed

+196
-1
lines changed

6 files changed

+196
-1
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Publish MongoDB Docker images
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: ["main"]
7+
paths:
8+
- mongodb/Dockerfile.*
9+
- .github/workflows/docker-mongodb.yml
10+
11+
env:
12+
REGISTRY: index.docker.io
13+
IMAGE_NAME: binaryoverload/mongodb-client
14+
15+
permissions:
16+
id-token: write
17+
attestations: write
18+
19+
jobs:
20+
publish_mongodb:
21+
name: Publish MongoDB Images
22+
runs-on: ubuntu-latest
23+
strategy:
24+
matrix:
25+
os: [ubuntu, alpine]
26+
27+
steps:
28+
- name: Check out the repo
29+
uses: actions/checkout@v4
30+
31+
- name: Log in to Docker Hub
32+
uses: docker/login-action@v3
33+
with:
34+
username: ${{ secrets.DOCKER_USERNAME }}
35+
password: ${{ secrets.DOCKER_PASSWORD }}
36+
37+
- name: Extract metadata (tags, labels) for Docker
38+
id: meta
39+
uses: docker/metadata-action@v5
40+
with:
41+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42+
tags: |
43+
type=raw,value=latest,enable=${{ matrix.os == 'ubuntu' }}
44+
type=raw,value=${{ matrix.os }}
45+
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v3
48+
49+
- name: Build and push Docker image
50+
id: push
51+
uses: docker/build-push-action@v5
52+
with:
53+
context: ./mongodb
54+
platforms: linux/amd64,linux/arm64
55+
file: ./mongodb/Dockerfile.${{ matrix.os }}
56+
push: true
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}
59+
cache-from: type=gha
60+
cache-to: type=gha,mode=max
61+
62+
- name: Attest
63+
uses: actions/attest-build-provenance@v2
64+
id: attest
65+
with:
66+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
67+
subject-digest: ${{ steps.push.outputs.digest }}
68+
push-to-registry: true

.github/workflows/dockerhub-description.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
package: [postgresql-client, mariadb-client, backup-client]
16+
package:
17+
[postgresql-client, mariadb-client, mongodb-client, backup-client]
1718
include:
1819
- package: postgresql-client
1920
description: A PostgreSQL client image with built-in file transfer and backup tools.
@@ -23,6 +24,10 @@ jobs:
2324
description: A MariaDB client image with built-in file transfer and backup tools.
2425
readme: ./mariadb/README.md
2526

27+
- package: mongodb-client
28+
description: A MongoDB client image with built-in file transfer and backup tools.
29+
readme: ./mongodb/README.md
30+
2631
- package: backup-client
2732
description: An image with built-in file transfer and backup tools.
2833
readme: ./backup/README.md

mongodb/Dockerfile.alpine

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM alpine:latest
2+
3+
ARG TARGETARCH
4+
5+
RUN apk update && apk add zip gzip xz curl wget rsync openssl gpg ca-certificates lsb-release mongodb-tools nodejs npm && npm i -g mongosh
6+
7+
# Install rclone
8+
RUN curl -sSL https://downloads.rclone.org/rclone-current-linux-$TARGETARCH.zip -o rclone.zip && \
9+
unzip rclone.zip && \
10+
install -Dm755 rclone-*-linux-$TARGETARCH/rclone /usr/bin/rclone && \
11+
rm -rf rclone.zip rclone-*-linux-$TARGETARCH

mongodb/Dockerfile.ubuntu

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM ubuntu:latest AS base
2+
3+
ARG TARGETARCH
4+
5+
# Install common utils and MongoDB
6+
RUN apt-get -y update && \
7+
apt-get -y install zip gzip xz-utils curl wget rsync openssl gpg ca-certificates lsb-release && \
8+
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor && \
9+
echo "deb [ arch=$TARGETARCH signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] http://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/8.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-8.0.list && \
10+
apt-get -y update && \
11+
apt-get -y install mongodb-org-tools mongodb-mongosh && \
12+
rm -rf /var/lib/apt/lists/*
13+
14+
# Install rclone
15+
RUN curl -sSL https://downloads.rclone.org/rclone-current-linux-$TARGETARCH.zip -o rclone.zip && \
16+
unzip rclone.zip && \
17+
install -Dm755 rclone-*-linux-$TARGETARCH/rclone /usr/bin/rclone && \
18+
rm -rf rclone.zip rclone-*-linux-$TARGETARCH

mongodb/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# binaryoverload/mongodb-client
2+
3+
![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/binaryoverload/docker-backup-clients/docker-mongodb.yml) [![Docker Hub](https://img.shields.io/badge/Docker%20Hub-gray?logo=docker)](https://hub.docker.com/r/binaryoverload/mongodb-client) [![GitHub](https://img.shields.io/badge/GitHub-black?logo=github&logoColor=white)](https://github.com/binaryoverload/docker-backup-clients/)
4+
5+
A Docker image for all of the MongoDB client executables, including:
6+
7+
# cmd:bsondump
8+
9+
<!-- cmd:mongodump
10+
cmd:mongoexport
11+
cmd:mongofiles
12+
cmd:mongoimport
13+
cmd:mongorestore
14+
cmd:mongostat
15+
cmd:mongotop -->
16+
17+
- `mongosh` - The mongodb shell, a command-line interface for interacting with a mongodb server
18+
- `mongodump` - Dump a database or a collection of databases to a file
19+
- `mongorestore` - Restore a database from a dump file
20+
- `bsondump` - Convert BSON files to JSON
21+
- `mongoexport` - Export data from a database to a file
22+
- `mongofiles` - Upload and download files to and from a mongodb server
23+
- `mongoimport` - Import data from a file to a database
24+
- `mongostat` - Display statistics about a mongodb server
25+
- `mongotop` - Monitor the performance of a mongodb server
26+
27+
The image also includes common file transfer utilities to allow use of this image for backup and restore operations, including:
28+
29+
- `curl`, `wget` - Download files from the internet
30+
- `tar`, `gzip`, `zip` and `xz` - Archive and compress files
31+
- `openssl` and `gpg` - Encrypt and decrypt files
32+
- `rsync` - Synchronize files and directories between two locations
33+
- `rclone` - https://rclone.org/ - Sync files and directories to and from cloud storage providers
34+
35+
This image is intended to be used as a base image for running MongoDB scripts and as such is deployed in both Ubuntu (Default) and Alpine distro variants.

mongodb/build_all_images.ps1

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
$oses = @("ubuntu", "alpine")
2+
3+
$successfulBuilds = @()
4+
$failedBuilds = @()
5+
6+
foreach ($os in $oses) {
7+
$tags = @("binaryoverload/mongodb-client:$os")
8+
if ($os -eq "ubuntu") {
9+
$tags += "binaryoverload/mongodb-client:latest"
10+
}
11+
12+
Write-Host ""
13+
Write-Host "───────────────────────────────────────────────"
14+
Write-Host "Building image for OS=$os"
15+
Write-Host "Tags: $($tags -join ', ')"
16+
Write-Host "───────────────────────────────────────────────"
17+
18+
$tagArgs = $tags | ForEach-Object { "--tag=$_" }
19+
20+
$buildArgs = @(
21+
"buildx", "build",
22+
"--file", "./Dockerfile.$os"
23+
) + $tagArgs + "."
24+
25+
Write-Host "Running Docker command:"
26+
Write-Host "docker $($buildArgs -join ' ')"
27+
28+
docker @buildArgs
29+
30+
if ($LASTEXITCODE -ne 0) {
31+
Write-Warning "Build failed for OS=$os"
32+
$failedBuilds += "$os"
33+
}
34+
else {
35+
$successfulBuilds += "$os"
36+
}
37+
38+
Write-Host ""
39+
}
40+
41+
# Summary report
42+
Write-Host "`n=================== Build Summary ==================="
43+
Write-Host "✅ Successful builds:"
44+
if ($successfulBuilds.Count -eq 0) {
45+
Write-Host " (none)"
46+
}
47+
else {
48+
$successfulBuilds | ForEach-Object { Write-Host " $_" }
49+
}
50+
51+
Write-Host "`n❌ Failed builds:"
52+
if ($failedBuilds.Count -eq 0) {
53+
Write-Host " (none)"
54+
}
55+
else {
56+
$failedBuilds | ForEach-Object { Write-Host " $_" }
57+
}
58+
Write-Host "======================================================`n"

0 commit comments

Comments
 (0)