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

Experiment #1

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ansible.python.interpreterPath": "c:\\Users\\Leon\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe"
}
2 changes: 2 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[defaults]
COLLECTIONS_PATHS = /usr/share/ansible/collections:/usr/share/automation-controller/collections/ansible_collections
3 changes: 3 additions & 0 deletions aws/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ansible.python.interpreterPath": "c:\\Users\\Leon\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe"
}
17 changes: 17 additions & 0 deletions aws/ami_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: List AWS AMIs with AMI IDs
hosts: localhost
gather_facts: no
# vars:
# ami_di:
# aws_region:
tasks:
- name: Gather AWS AMI facts
amazon.aws.ec2_ami_info:
image_ids: "{{ ami_id }}"
region: "{{ aws_region }}"
register: ami_facts

- name: Display AMIs with their IDs
debug:
var: ami_facts
4 changes: 2 additions & 2 deletions aws/create_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
- name: find ec2 id and take a snapshot of it with tag demo
hosts: localhost
environment:
AWS_ACCESS_KEY: "{{a_key}}"
AWS_SECRET_KEY: "{{s_key}}"
# AWS_ACCESS_KEY: "{{a_key}}"
# AWS_SECRET_KEY: "{{s_key}}"
AWS_REGION: "{{region_az}}"
tasks:
- name: find ec2 id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
tasks:
- name: Create App Service on Linux with Java Runtime
azure_rm_webapp:
resource_group: "{{ resource_group }}"
name: "{{ webapp_name }}"
resource_group: "{{ resource_group }}"
name: "{{ webapp_name }}" # This has to be unique
plan:
resource_group: "{{ resource_group }}"
name: "{{ plan_name }}"
Expand Down
8 changes: 8 additions & 0 deletions azure/appService-with-trafficManager/remove_appservice.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- hosts: localhost
connection: local
tasks:
- name: Delete App Service
azure_rm_webapp:
resource_group: "{{ resource_group }}"
name: "{{ webapp_name }}"
state: absent
8 changes: 8 additions & 0 deletions azure/general/get-resource-info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Get Azure Resources
hosts: localhost
connection: local
tasks:
- name: Get facts for one resource group
azure.azcollection.azure_rm_resourcegroup_info:
name: "{{ myResourceGroup }}"
5 changes: 4 additions & 1 deletion azure/webapp-and-cosmosdb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,8 @@ podman run -itd -e MONGO_DBCONNECTION= --name todo-app IMGAE_NAME:latest
podman tag localhost/nodejs-todo XXX.azurecr.io/demo/nodejs-todo
```
```
podman push XXX.azurecr.io/ossdemo/nodejs-to
podman push XXX.azurecr.io/demo/nodejs-todo
```
```
skopeo inspect docker://XXX.azurecr.io/demo/nodejs-todo:latest
```
3 changes: 3 additions & 0 deletions jenkins/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ansible.python.interpreterPath": "c:\\Users\\Leon\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe"
}
57 changes: 57 additions & 0 deletions jenkins/app_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
- name: Create new ACME Corp release
hosts: controller.acme.example.com
gather_facts: false

module_defaults:
ansible.builtin.uri:
url_username: "{{ student_user }}"
url_password: "{{ student_password }}"
body_format: json
force_basic_auth: true
validate_certs: false

tasks:
- name: Check if Gitea student-token exists - {{ student_user }}
ansible.builtin.uri:
url: "{{ repo_url }}/api/v1/users/{{ student_user }}/tokens"
method: GET
status_code: 200
register: __current_user_token

- name: Remove existing student-token - {{ student_user }}
ansible.builtin.uri:
url: "{{ repo_url }}/api/v1/users/{{ student_user }}/tokens/student-token"
method: DELETE
body:
name: student-token
status_code: [204]
register: __user_token
when: (__current_user_token.json | length > 0) and (__current_user_token.json[0]["name"] == "student-token")

- name: Create Gitea token - {{ student_user }}
ansible.builtin.uri:
url: "{{ repo_url }}/api/v1/users/{{ student_user }}/tokens"
method: POST
body:
name: student-token
status_code: [201]
register: __user_token

- name: Create new ACME release
ansible.builtin.uri:
url: "{{ repo_url }}/api/v1/repos/{{ student_user }}/acme_corp/releases"
method: POST
headers:
Authorization: token "{{ __user_token.json["sha1"] }}"
body:
'{"target_commitish": "main",
"name": "ACME Corp Patch Release {{ tag_name }}",
"draft": false,
"prerelease": false,
"tag_name": "{{ tag_name }}"}'
status_code: 201
register: __result
until: __result.status == 201
retries: 3
delay: 3
16 changes: 16 additions & 0 deletions jenkins/configure_jenkins_job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Configure ACMECorp Jenkins job
hosts: controller.acme.example.com
gather_facts: false

tasks:
- name: Create a jenkins job using basic authentication
environment:
PYTHONHTTPSVERIFY: 0
community.general.jenkins_job:
config: "{{ lookup('file', 'acme.xml') }}"
name: ACMECorp
user: "{{ student_user }}"
password: "{{ student_password }}"
url: "{{ ciserver_url }}"
validate_certs: false
Empty file.
25 changes: 25 additions & 0 deletions jenkins/deploy_acme_app,yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: Deploy ACME App
hosts: webservers
gather_facts: false

tasks:
- name: Extract download
ansible.builtin.unarchive:
src: "https://gitea:8443/{{ student_user }}/acme_corp/archive/{{ tag_name }}.tar.gz"
remote_src: true
owner: "{{ student_user }}"
group: "{{ student_user }}"
dest: /usr/local/
validate_certs: false

- name: Create database migrations
community.general.django_manage:
command: migrate
project_path: /usr/local/acme_corp/app/lets_quiz
virtualenv: "{{ acme_venv }}"

- name: Run the application
ansible.builtin.shell:
cmd: "nohup {{ acme_venv }}/bin/python3 manage.py runserver 0.0.0.0:8000 &"
chdir: /usr/local/acme_corp/app/lets_quiz
79 changes: 79 additions & 0 deletions jenkins/groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env groovy

pipeline {
agent any
stages {
stage('SCM Get Code') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: 'https://gitea:8443/student/acme_corp.git']]])
}
}

stage('Installing packages') {
steps {
script {
sh '/usr/bin/python3 -m pip install -r playbooks/files/requirements_test.txt'
}
}
}

stage('Static Code Checking') {
steps {
script {
sh 'find . -name \\*.py | xargs /usr/bin/python3 -m pylint --load-plugins=pylint_django -f parseable | tee pylint.log'
recordIssues(
tool: pyLint(pattern: 'pylint.log'),
failTotalHigh: 10,
)
}
}
}
stage('Build and Tag') {
steps {
withCredentials([gitUsernamePassword(credentialsId: 'gitea_repo', gitToolName: 'git')]) {
sh """
git reset --hard HEAD
git checkout main
git pull origin main --force --rebase
git fetch --tags --all --prune
git config --replace-all user.name ${env.GIT_USERNAME}
git config --replace-all user.email ${env.GIT_USERNAME}
cd app && /usr/bin/python3 -m bumpversion --config-file setup.cfg --allow-dirty --verbose minor --list > build_vars.env

"""
script {
def build_vars = readProperties file: 'app/build_vars.env'
env.newPkgVersion = build_vars.new_version
env.pkgVersion = build_vars.current_version
echo " CURRENT - ${pkgVersion}"
echo " NEW - ${newPkgVersion}"
}
sh """
git tag --force v${newPkgVersion}
git add .
git commit -m"Bump version from v${pkgVersion} to v${newPkgVersion}"
git push --force origin main v${newPkgVersion}
"""
}
}
}

stage('Controller - DevOps') {
steps {
ansibleTower(
towerServer: 'ACME Corp controller',
templateType: 'workflow',
jobTemplate: 'DevOps Workflow',
importTowerLogs: true,
removeColor: false,
verbose: true,
extraVars: '''---
pkg_version: $pkgVersion
tag_name: $newPkgVersion
'''
)
}
}
}

}
23 changes: 23 additions & 0 deletions jenkins/restart_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- name: Restart the ACMECorp DevOps workflow
hosts: controller.acme.example.com

tasks:
- name: Create temp repo file
ansible.builtin.template:
src: restart.tmp.j2
dest: "/home/{{ repo_user }}/acme_corp/restart.tmp"
owner: "{{ repo_user }}"
group: "{{ repo_user }}"
mode: '0644'

- name: Commit and push file to repo
ansible.builtin.command:
cmd: "{{ item }}"
chdir: "/home/{{ repo_user }}/acme_corp"
become: true
become_user: "{{ repo_user }}"
loop:
- "git add ."
- "git commit -m'Restart the workflow'"
- "git push -u origin main --force"