Commit c2800cf0 authored by John Jarvis's avatar John Jarvis Committed by Andrew Newdigate

Jarv/update ops instance

parent 3664faf4
This script is for populating repositories on the ops instance
it creates pull mirrors for every project, and populates CICD vars
How to use:
1. Create ops-instance.env from ops-instance.env.example
1. Copy it to the ops instance
1. Create a list of repo paths that you want to sync, use the ``
script and drop the file in /tmp/projects.list
1. Run `update-ops-gitlab-net-projects.rb` on the rails console by running
`gitlab-rails runner update-ops-gitlab-net-projects.rb`
#!/usr/bin/env bash
# 2807845 for security-tools
for group in 2807845 gitlab-cookbooks gl-infra; do
pages=$(curl -sI "$group/projects?private_token=$GITLAB_PRIVATE_TOKEN" | perl -ne 'm/X-Total-Pages: (\d+)/ && print $1')
for i in $(seq 1 "$pages"); do
for p in $(curl -s "$group/projects?private_token=$GITLAB_PRIVATE_TOKEN&page=$i" | jq -r '.[] | .path_with_namespace'); do
echo ${p}
# Add other paths that we want to mirror but without grabbing the entire group
echo "gitlab-com/influxdb-relay"
echo "gitlab-com/runbooks"
# The following must be set in your environment, get the values from 1password
# search for ops-gitlab-net system account for
# copy this file to ops-instance.env
## You must have the following set in your environment to use this script
raise "Environment not set, aborting!" unless ENV['OPS_PRIVATE_TOKEN'] && ENV['CI_PRIVATE_KEY'] && ENV['DIGITALOCEAN_ACCESS_TOKEN']
u = User.find_by(username: 'ops-gitlab-net')"/tmp/projects.list").each_line do |full_path|
full_path = full_path.chomp
group_path = File.dirname(full_path)
path = File.basename(full_path)
unless Group.find_by_full_path(group_path)
puts "Warning, group #{group_path} does not exist! - skipping"
p = Project.find_by_full_path(full_path)
unless p
p =, path: path, visibility_level: Gitlab::VisibilityLevel::INTERNAL, description: "Created by ops automation", namespace_id: Group.find_by_full_path(group_path).id).execute
p.mirror = true
p.only_mirror_protected_branches = false
p.mirror_user = u
p.mirror_trigger_builds = true
p.import_url = "https://ops-gitlab-net:#{ENV['OPS_PRIVATE_TOKEN']}{full_path}" 'CI_PRIVATE_KEY', value: ENV['CI_PRIVATE_KEY']) unless p.variables.find_by(key: 'CI_PRIVATE_KEY') 'DIGITALOCEAN_ACCESS_TOKEN', value: ENV['DIGITALOCEAN_ACCESS_TOKEN']) unless p.variables.find_by(key: 'DIGITALOCEAN_ACCESS_TOKEN')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment