Skip to content

Commit 275182a

Browse files
committed
add docker image, continuous deployment, update documentation
1 parent 0c76d18 commit 275182a

File tree

11 files changed

+160
-79
lines changed

11 files changed

+160
-79
lines changed

.travis.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
if [ "${1}" == "install" ]; then
4+
! docker pull viderum/ckan-cloud-operator:latest && echo Failed to pull image && exit 1
5+
echo Great Success! && exit 0
6+
7+
elif [ "${1}" == "script" ]; then
8+
! docker build --cache-from viderum/ckan-cloud-operator:latest -t ckan-cloud-operator . && echo Failed to build image && exit 1
9+
echo Great Success! && exit 0
10+
11+
elif [ "${1}" == "deploy" ]; then
12+
TAG="${TRAVIS_TAG:-${TRAVIS_COMMIT}}"
13+
docker tag ckan-cloud-operator "viderum/ckan-cloud-operator:${TAG}" &&\
14+
docker push "viderum/ckan-cloud-operator:${TAG}"
15+
[ "$?" != "0" ] && echo Failed to tag and push && exit 1
16+
if [ "${TRAVIS_BRANCH}" == "master" ]; then
17+
docker tag ckan-cloud-operator viderum/ckan-cloud-operator:latest &&\
18+
docker push viderum/ckan-cloud-operator:latest
19+
[ "$?" != "0" ] && echo Failed to tag and push && exit 1
20+
fi
21+
echo Great Success! && exit 0
22+
23+
else
24+
echo invalid arguments && exit 1
25+
26+
fi

.travis.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
language: bash
2+
sudo: required
3+
env:
4+
global:
5+
- TRAVIS_CI_OPERATOR=1
6+
- secure: "L2+magDtNAe7hKqOfCIkFEFkC01gjMhQsQbChwFd1ZEPa4tqX0yNgCoflghYIVfORsol/Uw3LRumiQNnJLGH4ft3NS7/azBWYLCbQkZduqJhFqYGbBuVIYlQTe1ZjrIxxV/McP0Fadha7fSS2AiyrVuPbvZSAPU0mCLz7LZazisYJg7dqNNZZTkvLEKbi0t6u+saDGUdvFqWlxG93QRJFpd4oCJ7l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YoK65SKkbK5TP4RjoJAeuLA0g38XvlVAYk5ZNJEeNw9YR0jOXWTq/GQJM3C1I="
8+
services:
9+
- docker
10+
install:
11+
- curl -L https://raw.githubusercontent.com/OriHoch/travis-ci-operator/master/travis_ci_operator.sh > $HOME/bin/travis_ci_operator.sh
12+
- bash $HOME/bin/travis_ci_operator.sh init
13+
- travis_ci_operator.sh docker-login
14+
- bash .travis.sh install
15+
script:
16+
- bash .travis.sh script
17+
deploy:
18+
skip_cleanup: true
19+
provider: script
20+
script: bash .travis.sh deploy
21+
on:
22+
all_branches: true
23+
condition: $TRAVIS_PULL_REQUEST = "false"

CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Contributing to CKAN Cloud
2+
3+
* Welcome to CKAN Cloud!
4+
* Contributions of any kind are welcome.
5+
* Please search for issues in this repository and [across the different CKAN Cloud repositories](https://github.com/search?q=repo%3AViderumGlobal%2Fckan-cloud-docker+repo%3AViderumGlobal%2Fckan-cloud-helm+repo%3AViderumGlobal%2Fckan-cloud-cluster&type=Issues)
6+
7+
## Continuous Deployment
8+
9+
Travis builds and pushes a docker image on every push.
10+
11+
Pushes are tagged with the commit SHA or published tag name.
12+
13+
Pushes to master are also tagged with `latest`.

Dockerfile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
FROM continuumio/miniconda3:4.5.11
22
RUN conda update -n base -c defaults conda
3+
RUN apt-get update && apt-get install -y gnupg bash-completion
4+
RUN echo "deb http://packages.cloud.google.com/apt cloud-sdk-stretch main" >> /etc/apt/sources.list.d/google-cloud-sdk.list && \
5+
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
6+
apt-get update -y && apt-get install -y google-cloud-sdk kubectl postgresql nano
37
COPY environment.yaml /environment.yaml
48
RUN conda env create -f /environment.yaml
5-
RUN apt-get update && apt-get install -y lsb-release gnupg
6-
RUN export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" && \
7-
echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \
8-
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
9-
apt-get update -y && apt-get install google-cloud-sdk -y &&\
10-
apt-get update -y && apt-get install -y kubectl
119
RUN echo conda activate ckan-cloud-operator >> ~/.bashrc &&\
1210
echo '[ -e /etc/ckan-cloud/.kube-config ] && export KUBECONFIG=/etc/ckan-cloud/.kube-config' >> ~/.bashrc &&\
13-
echo '[ -e /etc/ckan-cloud/gcloud-service-account.json ] && ! [ -z "${GCLOUD_SERVICE_ACCOUNT_EMAIL}" ] && gcloud --project="${GCLOUD_AUTH_PROJECT}" auth activate-service-account "${GCLOUD_SERVICE_ACCOUNT_EMAIL}" --key-file=/etc/ckan-cloud/gcloud-service-account.json' >> ~/.bashrc &&\
11+
echo '! [ -z "${KUBE_CONTEXT}" ] && kubectl config use-context "${KUBE_CONTEXT}" >/dev/null 2>&1' >> ~/.bashrc &&\
1412
mkdir /usr/src/ckan-cloud-operator
1513
COPY ckan_cloud_operator /usr/src/ckan-cloud-operator/ckan_cloud_operator
16-
COPY entrypoint.sh LICENSE MANIFEST.in README.md setup.py VERSION.txt /usr/src/ckan-cloud-operator/
14+
COPY entrypoint.sh setup.py /usr/src/ckan-cloud-operator/
1715
RUN . /opt/conda/etc/profile.d/conda.sh && conda activate ckan-cloud-operator &&\
1816
cd /usr/src/ckan-cloud-operator && python3 -m pip install -e .
1917
ENTRYPOINT ["/usr/src/ckan-cloud-operator/entrypoint.sh"]

MANIFEST.in

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.md

Lines changed: 85 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,88 @@ CKAN Cloud operator manages, provisions and configures Ckan Cloud instances and
44

55
## Install
66

7-
Create secret `ckan-infra` under namespace `ckan-cloud` with the following values:
8-
9-
* GCLOUD_SQL_INSTANCE_NAME
10-
* GCLOUD_SQL_PROJECT
11-
* POSTGRES_HOST
12-
* POSTGRES_USER
13-
* POSTGRES_PASSWORD
14-
* SOLR_HTTP_ENDPOINT
15-
* SOLR_NUM_SHARDS
16-
* SOLR_REPLICATION_FACTOR
17-
* DOCKER_REGISTRY_SERVER
18-
* DOCKER_REGISTRY_USERNAME
19-
* DOCKER_REGISTRY_PASSWORD
20-
* DOCKER_REGISTRY_EMAIL
21-
22-
## Run using Docker
23-
24-
You will need the following details:
25-
26-
* Path to .kube-config file with permissions to the relevant Kubernetes cluster
27-
* Path to Google Compute Cloud service account json with required permissions
28-
* The Google service account email associated with the service account json
29-
* The Google Project ID associated with the infrastructure and GKE cluster
7+
ckan-cloud-operator-env is used to install and manage CKAN Cloud operator environments on your local PC
308

31-
Run ckan-cloud-operator without arguments to get a help message:
9+
The only requirement is a .kube-config file with permissions to the relevant cluster
10+
11+
Install ckan-cloud-operator-env
12+
13+
```
14+
curl https://raw.githubusercontent.com/ViderumGlobal/ckan-cloud-operator/master/ckan-cloud-operator-env.sh \
15+
| sudo tee /usr/local/bin/ckan-cloud-operator-env &&\
16+
sudo chmod +x /usr/local/bin/ckan-cloud-operator-env
17+
```
18+
19+
Pull the latest Docker image
3220

3321
```
34-
docker run \
35-
-v /path/to/.kube-config:/etc/ckan-cloud/.kube-config \
36-
-v /path/to/glcoud-service-account.json:/etc/ckan-cloud/gcloud-service-account.json \
37-
-e GCLOUD_SERVICE_ACCOUNT_EMAIL= \
38-
-e GCLOUD_AUTH_PROJECT= \
39-
-it viderum/ckan-cloud-operator
22+
ckan-cloud-operator-env pull
4023
```
4124

42-
## Run locally
25+
Add an environment (to run on Minikube set PATH_TO_KUBECONFIG_FILE to minikube)
26+
27+
```
28+
sudo ckan-cloud-operator-env add <ENVIRONMENT_NAME> <PATH_TO_KUBECONFIG_FILE>
29+
```
30+
31+
Verify you are connected to the correct cluster
32+
33+
```
34+
ckan-cloud-operator cluster-info
35+
```
36+
37+
## Usage
38+
39+
Use the help message of the different commands for the reference documentation and usage examples
40+
41+
```
42+
ckan-cloud-operator --help
43+
```
44+
45+
Start a bash shell with completion
46+
47+
```
48+
ckan-cloud-operator bash
49+
```
50+
51+
This start a bash shell inside the ckan-cloud-operator Docker container, you can use bash completion inside this shell
52+
53+
```
54+
ckan-cloud-operator <TAB><TAB>
55+
```
56+
57+
## Managing multiple environments
58+
59+
ckan-cloud-operator-env supports managing multiple environments
60+
61+
Add environments using `ckan-cloud-operator-env add <ENVIRONMENT_NAME> <PATH_TO_KUBECONFIG_FILE>`
62+
63+
Each environment is accessible using executable `ckan-cloud-operator-<ENVIRONMENT_NAME>`
64+
65+
Activating an environment sets the `ckan-cloud-operator` executable to use to the relevant environment executable
66+
67+
```
68+
ckan-cloud-operator-env activate <ENVIRONMENT_NAME>
69+
```
70+
71+
## Initializing a cluster for ckan-cloud-operator
72+
73+
Kubernetes custom resource definitions are used for management of the CKAN Cloud resources
74+
75+
Run the following command to ensure the crds are installed on the cluster
76+
77+
```
78+
ckan-cloud-operator install-crds
79+
```
80+
81+
ckan-cloud-operator using a secret named `ckan-infra` under namespace `ckan-cloud` to get infrastrutcute secrets.
82+
83+
See the list of values in [ckan_cloud_operator/infra.py](ckan_cloud_operator/infra.py)
84+
85+
You can clone an infrastructure secret using `ckan-infra clone` command
86+
and some infrastructure secrets can be set using `ckan-infra set` command
87+
88+
## Run ckan-cloud-operator locally
4389

4490
Ensure you have `kubectl` and `gcloud` binaries, authenticated to the relevant gcloud account / kubernetes cluster.
4591

@@ -55,19 +101,20 @@ Install the Python package:
55101
python3 -m pip install -e .
56102
```
57103

58-
Run ckan-cloud-operator without arguments to get a help message:
104+
Authenticate the gcloud CLI to the relevant account:
59105

60106
```
61-
ckan-cloud-operator
107+
ckan-cloud-operator activate-gcloud-auth
62108
```
63109

64-
## Install custom resource definitions
110+
Run ckan-cloud-operator without arguments to get a help message:
65111

66-
Kubernetes custom resource definitions are used for management of the CKAN Cloud resources
112+
```
113+
ckan-cloud-operator
114+
```
67115

68-
Run the following command to ensure the crds are installed on the cluster
116+
Enable Bash completion
69117

70118
```
71-
ckan-cloud-operator install-crds
119+
eval "$(_CKAN_CLOUD_OPERATOR_COMPLETE=source ckan-cloud-operator)"
72120
```
73-

VERSION.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

entrypoint.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env bash
22

3-
source ~/.bashrc
4-
5-
exec ckan-cloud-operator "$@"
3+
if [ "${1}" == "bash" ]; then
4+
exec bash --init-file <(echo 'source ~/.bashrc; eval "$(_CKAN_CLOUD_OPERATOR_COMPLETE=source ckan-cloud-operator)"')
5+
else
6+
source ~/.bashrc
7+
exec ckan-cloud-operator "$@"
8+
fi

environment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dependencies:
66
- pip:
77
- pyyaml
88
- kubernetes
9+
- click

release.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)