Skip to content

Commit

Permalink
Remove mongo-sidecar image build from goreleaser (#2096)
Browse files Browse the repository at this point in the history
* Remove mongo-sidecar build from goreleaser config

Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>

* Update mongo sidecar Dockerfile to work with docker build

Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>

* Add docker image build steps in mongo-sidecar example

Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>

* Update examples/mongo-sidecar/README.md

* Update examples/mongo-sidecar/README.md

Co-authored-by: Vivek Singh <vsingh.ggits.2010@gmail.com>

---------

Signed-off-by: Prasad Ghangal <prasad.ghangal@gmail.com>
Co-authored-by: Vivek Singh <vsingh.ggits.2010@gmail.com>
  • Loading branch information
PrasadG193 and viveksinghggits authored Jun 12, 2023
1 parent 1dee05c commit be0f4e9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
10 changes: 0 additions & 10 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ dockers:
dockerfile: 'docker/kanister-kubectl/Dockerfile'
build_flag_templates:
- "--build-arg=TOOLS_IMAGE=ghcr.io/kanisterio/kanister-tools:{{ .Tag }}"
- ids:
- kando
image_templates:
- 'ghcr.io/kanisterio/mongo-sidecar:{{ .Tag }}'
dockerfile: 'docker/kanister-mongodb-replicaset/image/Dockerfile'
extra_files:
- 'docker/kanister-mongodb-replicaset/image/install.sh'
- 'docker/kanister-mongodb-replicaset/image/90forceyes'
- 'docker/kanister-mongodb-replicaset/image/config'
- 'docker/kanister-mongodb-replicaset/image/gbl_env.sh'
- ids:
- kando
image_templates:
Expand Down
3 changes: 1 addition & 2 deletions docker/kanister-mongodb-replicaset/image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ LABEL maintainer="Tom Manville <tom@kasten.io>"

USER root

ADD ./docker/kanister-mongodb-replicaset/image /kanister
ADD . /kanister

RUN /kanister/install.sh && rm -rf /kanister && rm -rf /tmp && mkdir /tmp

COPY --from=restic/restic:0.11.0 /usr/bin/restic /usr/local/bin/restic
ADD kando /usr/local/bin/

CMD ["tail", "-f", "/dev/null"]
5 changes: 4 additions & 1 deletion docker/kanister-mongodb-replicaset/image/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mv 90forceyes /etc/apt/apt.conf.d/

echo "================= Installing basic packages ==================="
apt-get update && \
apt-get install curl wget musl-dev python3 rsync -y
apt-get install curl wget musl-dev python3 rsync libdigest-sha-perl -y

echo "================= Installing Python packages ==================="
wget --progress=dot:mega https://bootstrap.pypa.io/pip/3.5/get-pip.py
Expand All @@ -32,6 +32,9 @@ echo "================= Install Mongo Tools ==================="
wget --progress=dot:mega https://github.com/Percona-Lab/mongodb_consistent_backup/releases/download/1.1.0/${mongo_deb}
dpkg -i ./${mongo_deb}

echo "================= Install Kanister Tools ==================="
curl https://raw.githubusercontent.com/kanisterio/kanister/master/scripts/get.sh | bash

echo "================= Cleaning package lists ==================="
apt-get clean
apt-get autoclean
Expand Down
36 changes: 30 additions & 6 deletions examples/mongo-sidecar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,31 @@

This is an example of using Kanister to backup and restore MongoDB. In this example, we will deploy MongoDB with a sidecar container. This sidecar container will include the necessary tools to store protected data from MongoDB into an S3 bucket in AWS. Note that a sidecar container is not required to use Kanister, but rather is just one of several ways to access tools needed to protect the application. See other examples in the examples folder for alternative ways.

### 1. Deploy the Application

### Prerequisites

- Kubernetes 1.20+
- PV provisioner support in the underlying infrastructure
- Kanister controller version 0.92.0 installed in your cluster, let's assume in Namespace `kanister`
- Kanctl CLI installed (https://docs.kanister.io/tooling.html#install-the-tools)


### 1. Build and push mongo-sidecar docker image

The MongoDB application needs to be instrumented with the required tooling in order to get protected with Kanister. Follow the steps below to build a `mongo-sidecar` docker image which has all the necessary tools installed.

```bash
# Clone Kanister Github repo locally
$ git clone https://github.com/kanisterio/kanister.git <path_to_kanister>

# Build mongo-sidecar docker image
$ docker build -t <registry>/<repository>/mongo-sidecar:<tag_name> <path_to_kanister>/docker/kanister-mongodb-replicaset/image/
$ docker push <registry>/<repository>/mongo-sidecar:<tag_name>
```

### 2. Deploy the Application

Replace `<registry>`, `<repository>` and `<tag_name>` placeholders with actual values in `mongo-cluster.yaml`.

The following command deploys the example MongoDB application in `default` namespace:
```bash
Expand All @@ -26,7 +50,7 @@ $ mongo test --quiet --eval "db.restaurants.find()"
{ "_id" : ObjectId("5a1dd0719dcbfd513fecf87c"), "name" : "Roys", "cuisine" : "Hawaiian", "id" : "8675309" }
```
### 2. Protect the Application
### 3. Protect the Application
Next create a Blueprint which describes how backup and restore actions can be executed on this application. The Blueprint for this application can be found at `./examples/mongo-sidecar/blueprint.yaml`. Notice that the backup action of the Blueprint references the S3 location specified in the ConfigMap in `./examples/mongo-sidecar/s3-location-configmap.yaml`. In order for this example to work, you should update the path field of s3-location-configmap.yaml to point to an S3 bucket to which you have access. You should also update `secrets.yaml` to include AWS credentials that have read/write access to the S3 bucket. Provide your AWS credentials by setting the corresponding data values for `aws_access_key_id` and `aws_secret_access_key` in `secrets.yaml`. These are encoded using base64. The following commands will create a ConfigMap, Secrets and a Blueprint in controller's namespace:
Expand Down Expand Up @@ -57,7 +81,7 @@ NAME KIND
mongo-backup-12046 ActionSet.v1alpha1.cr.kanister.io
```
### 3. Disaster strikes!
### 4. Disaster strikes!
Let's say someone with fat fingers accidentally deleted the restaurants collection using the following command:
```bash
Expand All @@ -72,7 +96,7 @@ $ mongo test --quiet --eval "db.restaurants.find()"
# No entries should be found in the restaurants collection
```
### 4. Restore the Application
### 5. Restore the Application
To restore the missing data, we want to use the backup created in step 2. An easy way to do this is to leverage `kanctl`, a command-line tool that helps create ActionSets that depend on other ActionSets:
Expand All @@ -90,7 +114,7 @@ $ mongo test --quiet --eval "db.restaurants.find()"
{ "_id" : ObjectId("5a1dd0719dcbfd513fecf87c"), "name" : "Roys", "cuisine" : "Hawaiian", "id" : "8675309" }
```
### 5. Delete the Artifacts
### 6. Delete the Artifacts
The artifacts created by the backup action can be cleaned up using the following command:
Expand All @@ -100,4 +124,4 @@ actionset "delete-mongo-backup-12046-kf8mt" created
# View the status of the ActionSet
$ kubectl --namespace kanister get actionset delete-mongo-backup-12046-kf8mt -oyaml
```
```
2 changes: 1 addition & 1 deletion examples/mongo-sidecar/mongo-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ spec:
- bash
- -c
env:
image: ghcr.io/kanisterio/mongodb-sidecar:v0.2.0
image: <registry>/<repository>/mongo-sidecar:<tag_name>
name: mongo-tools-sidecar
- command:
- mongod
Expand Down

0 comments on commit be0f4e9

Please sign in to comment.