Skip to content

Commit

Permalink
Add github workflow to build and push MongoDB Atlas tools image (#2038)
Browse files Browse the repository at this point in the history
* Add mongodb-atlas image to ghcr.io registry
* Add github workflow to build and push MongoDB Atlas tools image
  • Loading branch information
shahpratikr authored May 9, 2023
1 parent cacd577 commit b9eee33
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 27 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/atlas-image-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: build-mongodb-atlas-tools-image

on:
workflow_dispatch:
inputs:
tag:
description: 'MongoDB Atlas image tag in the format x.y.z'
required: true
type: string

env:
REGISTRY: ghcr.io
IMAGE_NAME: kanisterio/mongodb-atlas

jobs:
check-files:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.changed-files.outputs.any_changed }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: tj-actions/changed-files@v35
name: Get changed files
id: changed-files
with:
files: docker/mongodb-atlas/Dockerfile

build:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
needs: check-files
if: needs.check-files.outputs.changed == 'true'
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Image metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha
{{date 'YYYY.MM.DD-HHmm'}}
${{ inputs.tag }}
- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: "{{defaultContext}}:docker/mongodb-atlas"
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
10 changes: 9 additions & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,12 @@ It is an on-demand workflow and needs to be run manually. This workflow expects
`image tag` value as an input.

The author updating the build image tag must raise a separate PR to update this
value for it to be used in the build process. It should be set it [here](https://github.com/kanisterio/kanister/blob/master/Makefile#L61).
value for it to be used in the build process. It should be set it [here](https://github.com/kanisterio/kanister/blob/master/Makefile#L61).

## Build MongoDB Atlas tools image

The MongoDB Atlas image [workflow](.github/workflows/atlas-image-build.yaml)
is used to build and push a new Atlas tools image (`ghcr.io/kanisterio/mongodb-atlas`).
It is an on-demand workflow and needs to be run manually when there are changes
in [Atlas dockerfile](docker/mongodb-atlas/Dockerfile). This workflow expects
`image tag` value as an input.
21 changes: 0 additions & 21 deletions examples/mongodb-atlas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,10 @@ $ helm install kanister --namespace kanister --create-namespace \
kanister/kanister-operator --set image.tag=0.91.0
```

### Build a tools image to interact with MongoDB Atlas

We need to build a tools image that contains `mongosh`, `atlas` and other
related utilities so that it can be used to interact with the MongoDB Atlas
database to add data to it.
This image will also be used in the Blueprint to run the `atlas` backup and
restore related commands against the MongoDB Atlas database. Please execute the
commands below to build and push the image.

```bash
$ docker build -t <registry>/<repository>/mongodb-atlas:<tag_name> \
PATH_TO_KANISTER/docker/mongodb-atlas
$ docker push <registry>/<repository>/mongodb-atlas:<tag_name>
```

### Create Blueprint

Create Blueprint in the same namespace as the Kanister controller.

**NOTE:**

Please make sure that the `<registry>`, `<repository>` and `<tag_name>` in the
blueprint (`mongodb-atlas-blueprint.yaml`) are replaced with correct values of
the tools image that we built above.

```bash
$ kubectl create -f ./mongodb-atlas-blueprint.yaml -n kanister
```
Expand Down
10 changes: 5 additions & 5 deletions examples/mongodb-atlas/mongodb-atlas-blueprint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ actions:
name: mongoBackup
args:
namespace: "{{ .Object.metadata.namespace }}"
image: <registry>/<repository>/mongodb-atlas:<tag_name>
image: ghcr.io/kanisterio/mongodb-atlas:0.0.1
command:
- bash
- -o
Expand All @@ -42,7 +42,7 @@ actions:
name: waitForBackupToComplete
args:
namespace: "{{ .Object.metadata.namespace }}"
image: <registry>/<repository>/mongodb-atlas:<tag_name>
image: ghcr.io/kanisterio/mongodb-atlas:0.0.1
command:
- bash
- -o
Expand Down Expand Up @@ -95,7 +95,7 @@ actions:
namespace: '{{ .ArtifactsIn.backupOutput.KeyValue.appNamespace }}'
args:
namespace: "{{ .ArtifactsIn.backupOutput.KeyValue.appNamespace }}"
image: <registry>/<repository>/mongodb-atlas:<tag_name>
image: ghcr.io/kanisterio/mongodb-atlas:0.0.1
command:
- bash
- -o
Expand Down Expand Up @@ -127,7 +127,7 @@ actions:
name: waitForRestoreToComplete
args:
namespace: "{{ .ArtifactsIn.backupOutput.KeyValue.appNamespace }}"
image: <registry>/<repository>/mongodb-atlas:<tag_name>
image: ghcr.io/kanisterio/mongodb-atlas:0.0.1
command:
- bash
- -o
Expand Down Expand Up @@ -182,7 +182,7 @@ actions:
namespace: '{{ .ArtifactsIn.backupOutput.KeyValue.appNamespace }}'
args:
namespace: "{{ .ArtifactsIn.backupOutput.KeyValue.appNamespace }}"
image: <registry>/<repository>/mongodb-atlas:<tag_name>
image: ghcr.io/kanisterio/mongodb-atlas:0.0.1
command:
- bash
- -o
Expand Down

0 comments on commit b9eee33

Please sign in to comment.