Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gitlab #84

Merged
merged 7 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
gitlab-dev:
tags:
- meao
- gcp
only:
- gitlab
variables:
NAMESPACE: nucleus-dev
script:
- docker/bin/build_images.sh
- docker/bin/push2dockerhub.sh
- bin/update-config.sh

master:
tags:
- meao
- gcp
only:
- master
variables:
NAMESPACE: nucleus-dev
script:
- docker/bin/build_images.sh
- docker/bin/push2dockerhub.sh
- bin/update-config.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we can't have these two combined (adding an entry in only)? Or are they just separated for now to call out that one is testing and will be deleted later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed on zoom, let's keep both jobs for now, and we can use the gitlab branch in the furture for testing new versions of .gitlab-ci.yml outside of the master branch.


stage:
tags:
- meao
- gcp
only:
- stage
variables:
NAMESPACE: nucleus-stage
script:
- docker/bin/build_images.sh
- docker/bin/push2dockerhub.sh
- bin/update-config.sh

prod:
tags:
- meao
- gcp
only:
- prod
variables:
NAMESPACE: nucleus-prod
script:
- docker/bin/build_images.sh
- docker/bin/push2dockerhub.sh
- bin/update-config.sh
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ See the [full list of supported environment variables](https://docs.newrelic.com
## Kubernetes

https://github.com/mozmeao/nucleus-config/ has public examples of deployments in k8s clusters in AWS & GCP.


## Gitlab CI/CD

We have https://gitlab.com/mozmeao/nucleus/pipelines [set up as CI/CD for](https://gitlab.com/mozmeao/infra/blob/master/docs/gitlab_ci.md) https://github.com/mozilla/nucleus via this [.gitlab-ci.yml](https://github.com/mozilla/nucleus/blob/gitlab/.gitlab-ci.yml), which [updates the config repo](https://github.com/mozilla/nucleus/blob/gitlab/bin/update-config.sh) triggering https://gitlab.com/mozmeao/nucleus/pipelines configured by [.gitlab-ci.yml in the config repo](https://github.com/mozilla/nucleus-config/blob/master/.gitlab-ci.yml).
15 changes: 15 additions & 0 deletions bin/update-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -ex
# env vars: CLUSTER_NAME, CONFIG_BRANCH, CONFIG_REPO, NAMESPACE, DEPLOYMENT_YAML

. ${BASH_SOURCE%/*}/../docker/bin/set_git_env_vars.sh # sets DOCKER_IMAGE_TAG
pushd $(mktemp -d)
git clone --depth=1 -b ${CONFIG_BRANCH:=master} ${CONFIG_REPO:=github-mozmar-robot:mozmeao/nucleus-config} nucleus-config
cd nucleus-config

set -u
sed -i -e "s|image: .*|image: ${DOCKER_IMAGE_TAG}|" ${CLUSTER_NAME:=iowa-b}/${NAMESPACE:=nucleus-dev}/${DEPLOYMENT_YAML:=deploy.yaml}
git add ${CLUSTER_NAME}/${NAMESPACE}/${DEPLOYMENT_YAML}
git commit -m "set image to ${DOCKER_IMAGE_TAG} in ${CLUSTER_NAME}" || echo "nothing new to commit"
git push
popd
7 changes: 0 additions & 7 deletions docker/bin/build_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ function imageExists() {
return $?
}

function dockerRun() {
env_file="$1"
image_tag="mozorg/bedrock_${2}:${GIT_COMMIT}"
cmd="$3"
docker run --rm --user $(id -u) -v "$PWD:/app" --env-file "docker/envfiles/${env_file}.env" "$image_tag" bash -c "$cmd"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own edification, why do we no longer need this?


if ! imageExists; then
docker/bin/docker_build.sh --pull
fi
4 changes: 0 additions & 4 deletions docker/bin/push2dockerhub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ set -ex
BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $BIN_DIR/set_git_env_vars.sh

DOCKER_USERNAME="${DOCKER_USERNAME:-mozjenkins}"

docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming these are now set in the cluster?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the credentials are stored on the runner instances and interactive login using a password from an env var is neither needed nor desired.


# Push to docker hub
docker push $DOCKER_IMAGE_TAG

Expand Down