1+ name : Initialize Repository
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ github_org_name :
7+ type : string
8+ required : true
9+ description : ' GitHub Org Name'
10+ repo_name :
11+ type : string
12+ required : true
13+ description : ' New Project Repository Name'
14+ mlops_lifecycle_repo_name :
15+ default : aiops
16+ type : string
17+ description : ' Lifecycle Repository name'
18+ mlops_project_template_repo_name :
19+ default : aiops-project-template
20+ type : string
21+ description : ' Project Templates repo'
22+ project_type :
23+ default : classical
24+ description : ' ML Project Type'
25+ required : true
26+ type : choice
27+ options :
28+ - classical
29+ - cv
30+ - nlp
31+ mlops_interface :
32+ default : aml-cli-v2
33+ description : ' MLOps Interface'
34+ required : true
35+ type : choice
36+ options :
37+ - aml-cli-v2
38+ - python-sdk-v1
39+ - python-sdk-v2
40+ - rai-aml-cli-v2
41+ infrastructure_provisioner :
42+ default : terraform
43+ description : ' Infrastructure Provisioner'
44+ required : true
45+ type : choice
46+ options :
47+ - bicep
48+ - terraform
49+ infrastructure_provider :
50+ default : Azure
51+ description : ' Infrastructure Provider'
52+ required : true
53+ type : choice
54+ options :
55+ - Azure
56+ - AWS
57+ - Google
58+ orchestration_tool :
59+ default : github-actions
60+ description : ' Orchestration Tool'
61+ required : true
62+ type : choice
63+ options :
64+ - github-actions
65+ - azure-devops
66+ project_name :
67+ type : string
68+ required : false
69+ description : ' ADO Project Name'
70+ organisation_name :
71+ type : string
72+ required : false
73+ description : ' ADO Organisation Name'
74+
75+ jobs :
76+ Initialise_Repository :
77+ runs-on : ubuntu-latest
78+
79+ permissions : write-all
80+
81+ steps :
82+
83+ - name : Checkout new project repository
84+ uses : actions/checkout@v4
85+ with :
86+ repository : ${{ inputs.github_org_name }}/${{ inputs.repo_name }}
87+ path : ${{ inputs.repo_name }}
88+
89+ - name : Checkout MLOpsLifecycle repository
90+ uses : actions/checkout@v4
91+ with :
92+ repository : ${{ inputs.github_org_name }}/${{ inputs.mlops_lifecycle_repo_name }}
93+ path : ${{ inputs.mlops_lifecycle_repo_name }}
94+
95+ - name : Checkout MLOps project template repository
96+ uses : actions/checkout@v4
97+ with :
98+ repository : ${{ inputs.github_org_name }}/${{ inputs.mlops_project_template_repo_name }}
99+ path : ${{ inputs.mlops_project_template_repo_name }}
100+
101+ - name : Initialise your repository
102+ run : |
103+ github_org_name=${{ inputs.github_org_name }}
104+ repo_name=${{ inputs.repo_name }}
105+ project_type=${{ inputs.project_type }}
106+ mlops_interface=${{ inputs.mlops_interface }}
107+ template_repo=${{ inputs.mlops_project_template_repo_name }}
108+ infrastructure_provisioner=${{ inputs.infrastructure_provisioner }}
109+ orchestration=${{ inputs.orchestration_tool }}
110+
111+ git config --global user.email "github-action@github.com"
112+ git config --global user.name "GitHub Action"
113+
114+ mkdir files_to_keep
115+ mkdir files_to_delete
116+
117+ cd $template_repo
118+ cp --parents -r infrastructure/$infrastructure_provisioner ../files_to_keep
119+ cp --parents -r $project_type/$mlops_interface ../files_to_keep
120+ cp config-infra-dev.yml ../files_to_keep
121+ cp config-infra-prod.yml ../files_to_keep
122+ cd ..
123+ mv $template_repo/* files_to_delete
124+
125+ cd $repo_name
126+ git checkout -b main
127+ cd ..
128+ rm -rf $repo_name/*
129+ mv files_to_keep/* $repo_name
130+ cd $repo_name
131+
132+ # Move files to appropriate level
133+ mv $project_type/$mlops_interface/data-science data-science
134+ mv $project_type/$mlops_interface/mlops mlops
135+ mv $project_type/$mlops_interface/data data
136+
137+ if [[ "$mlops_interface" == "python-sdk-v1" ]]; then
138+ mv $project_type/$mlops_interface/config-aml.yml config-aml.yml
139+ fi
140+
141+ rm -rf $project_type
142+
143+ mv infrastructure/$infrastructure_provisioner $infrastructure_provisioner
144+ rm -rf infrastructure
145+ mv $infrastructure_provisioner infrastructure
146+
147+ if [[ "$orchestration" == "github-actions" ]]; then
148+ mkdir -p .github/workflows/
149+ mv mlops/github-actions/* .github/workflows/
150+ mv infrastructure/github-actions/* .github/workflows/
151+ rm -rf mlops/github-actions
152+ rm -rf infrastructure/github-actions
153+ elif [[ "$orchestration" == "azure-devops" ]]; then
154+ rm -rf mlops/github-actions
155+ rm -rf infrastructure/github-actions
156+ fi
157+
158+ git init -b main
159+ git add . && git commit -m 'initial commit'
160+
161+ echo "Check if the Repository Exists and Create if it doesn't"
162+
163+ if gh repo view $github_org_name/$repo_name > /dev/null 2>&1; then
164+ echo "Repository $repo_name exists."
165+ else
166+ echo "Repository $repo_name does not exist. Creating it."
167+ gh repo create $github_org_name/$repo_name --private
168+ fi
169+
170+ git remote add origin https://github.com/${github_org_name}/${repo_name}.git
171+ git push --set-upstream origin main
172+
173+ - name : Create GitHub Actions workflows for MLOps and Infrastructure
174+ if : inputs.orchestration_tool == 'github-actions'
175+ run : |
176+ github_org_name=${{ inputs.github_org_name }}
177+ repo_name=${{ inputs.repo_name }}
178+ path_to_infrastructure_pipelines=infrastructure/github-actions
179+ path_to_mlops_pipelines=mlops/github-actions
180+
181+ # Create pipeline folders
182+ mkdir -p .github/workflows/$repo_name/infrastructure
183+ mkdir -p .github/workflows/$repo_name/mlops
184+
185+ # Create MLOps Pipelines
186+ mlops_pipeline_files=$(ls $path_to_mlops_pipelines)
187+ for file in $mlops_pipeline_files
188+ do
189+ gh workflow create --repo "${github_org_name}/${repo_name}" \
190+ --content "$path_to_mlops_pipelines/$file" \
191+ --description "Automatically created pipeline for MLOps $file" \
192+ --name "${file%.*}"
193+ done
194+
195+ # Create Infrastructure Pipelines
196+ infra_pipeline_files=$(ls $path_to_infrastructure_pipelines)
197+ for file in $infra_pipeline_files
198+ do
199+ gh workflow create --repo "${github_org_name}/${repo_name}" \
200+ --content "$path_to_infrastructure_pipelines/$file" \
201+ --description "Automatically created pipeline for infra $file" \
202+ --name "${file%.*}"
203+ done
204+
205+ - name : Create Azure DevOps Pipelines for MLOps and Infrastructure
206+ if : inputs.orchestration_tool == 'azure-devops'
207+ run : |
208+ az login --service-principal -u ${{ secrets.AZURE_CLIENT_ID }} -p ${{ secrets.AZURE_CLIENT_SECRET }} --tenant ${{ secrets.AZURE_TENANT_ID }}
209+ repo_name=${{ inputs.repo_name }}
210+ project_name=${{ inputs.project_name }}
211+ organization_name=${{ inputs.organization_name }}
212+ path_to_infrastructure_pipelines=infrastructure/devops-pipelines
213+ path_to_mlops_pipelines=mlops/devops-pipelines
214+
215+ #Create Azure DevOps project if it does not exist
216+ project_exists=$(az devops project list --organization "https://dev.azure.com/${organization_name}" --output tsv --query "value[?name=='${project_name}'].name")
217+ if [ -z "$project_exists" ]; then
218+ az devops project create --name "${project_name}" --organization "https://dev.azure.com/${organization_name}"
219+ else
220+ echo "Project ${project_name} already exists."
221+ fi
222+
223+ # Create MLOps Pipelines
224+ mlops_pipeline_files=$(ls $path_to_mlops_pipelines)
225+ for file in $mlops_pipeline_files
226+ do
227+ az pipelines create \
228+ --name ${file%.*} \
229+ --description "Automatically created pipeline for MLOps $file" \
230+ --project $project_name \
231+ --organization "https://dev.azure.com/${organization_name}" \
232+ --repository $repo_name \
233+ --branch main \
234+ --yml-path $path_to_mlops_pipelines/$file \
235+ --repository-type tfsgit \
236+ --skip-first-run true
237+ done
238+
239+ # Create Infrastructure Pipelines
240+ infra_pipeline_files=$(ls $path_to_infrastructure_pipelines)
241+ for file in $infra_pipeline_files
242+ do
243+ az pipelines create \
244+ --name ${file%.*} \
245+ --description "Automatically created pipeline for infra $file" \
246+ --project $project_name \
247+ --organization "https://dev.azure.com/${organization_name}" \
248+ --repository $repo_name \
249+ --branch main \
250+ --yml-path $path_to_infrastructure_pipelines/$file \
251+ --repository-type tfsgit \
252+ --skip-first-run true
253+ done
0 commit comments