From 2660f55733ed9f3bbdf955ad4fc34f4be1a041f0 Mon Sep 17 00:00:00 2001 From: Neil Borromeo Date: Mon, 30 May 2022 17:37:50 +0800 Subject: [PATCH] first commit --- LICENSE | 21 ++++++ README.md | 1 + azure-pipelines.yml | 26 ++++++++ job_template.yml | 16 +++++ pipeline/azuredevops/Readme.md | 1 + pipeline/azuredevops/pipeline-docker.yml | 35 ++++++++++ pipeline/azuredevops/pipeline-java.yml | 19 ++++++ task_template.yml | 20 ++++++ terraform/azure/Readme.md | 1 + terraform/azure/main.tf | 84 ++++++++++++++++++++++++ terraform/azure/variables.tf | 24 +++++++ 11 files changed, 248 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 azure-pipelines.yml create mode 100644 job_template.yml create mode 100644 pipeline/azuredevops/Readme.md create mode 100644 pipeline/azuredevops/pipeline-docker.yml create mode 100644 pipeline/azuredevops/pipeline-java.yml create mode 100644 task_template.yml create mode 100644 terraform/azure/Readme.md create mode 100644 terraform/azure/main.tf create mode 100644 terraform/azure/variables.tf diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f9494ee --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 fortisitpl + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c673275 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# exercices \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..1cbd6a7 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,26 @@ +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +trigger: +- master + +pool: + vmImage: ubuntu-latest + +jobs: + - template: job_template.yml + + - job: Return + dependsOn: Set + variables: + modules: $[ dependencies.Set.outputs['setVars.MODULES'] ] + modules2: $[ dependencies.Set.outputs['setVars.MODULES2'] ] + steps: + - bash: | + modules=($(modules)) + for module in ${modules[@]};do + echo "MODULE: $module" + done + displayName: 'Print variable' diff --git a/job_template.yml b/job_template.yml new file mode 100644 index 0000000..09802bc --- /dev/null +++ b/job_template.yml @@ -0,0 +1,16 @@ +jobs: +- job: Set + steps: + - script: | + MODULES=("temporar" "tester") + echo "Modules: $MODULES" + echo "##vso[task.setvariable variable=MODULES;isoutput=true]${MODULES[@]}" + echo "##vso[task.setvariable variable=allModules]${MODULES[@]}" + displayName: 'Run a multi-line script' + name: setVars + - script: | + modules=($(allModules)) + echo ${modules[@]} + for module in ${modules[@]};do + echo "Module impacted: $module" + done diff --git a/pipeline/azuredevops/Readme.md b/pipeline/azuredevops/Readme.md new file mode 100644 index 0000000..ffd4d73 --- /dev/null +++ b/pipeline/azuredevops/Readme.md @@ -0,0 +1 @@ +# Place for azure devops pipelines diff --git a/pipeline/azuredevops/pipeline-docker.yml b/pipeline/azuredevops/pipeline-docker.yml new file mode 100644 index 0000000..49d1a07 --- /dev/null +++ b/pipeline/azuredevops/pipeline-docker.yml @@ -0,0 +1,35 @@ +trigger: +- main + +resources: +- repo: self + +variables: + # Container registry service connection established during pipeline creation + dockerRegistryServiceConnection: 'da808316-c62a-445b-ae0c-3ad87fd75a60' + imageRepository: 'javadocker' + containerRegistry: 'taskjava.azurecr.io' + dockerfilePath: '$(Build.SourcesDirectory)/app/Dockerfile' + tag: '$(Build.BuildId)' + + # Agent VM image name + vmImageName: 'ubuntu-latest' + +stages: +- stage: Build + displayName: Build and push stage + jobs: + - job: Build + displayName: Build + pool: + vmImage: $(vmImageName) + steps: + - task: Docker@2 + displayName: Build and push an image to container registry + inputs: + command: buildAndPush + repository: $(imageRepository) + dockerfile: $(dockerfilePath) + containerRegistry: $(dockerRegistryServiceConnection) + tags: | + $(tag) diff --git a/pipeline/azuredevops/pipeline-java.yml b/pipeline/azuredevops/pipeline-java.yml new file mode 100644 index 0000000..2131e92 --- /dev/null +++ b/pipeline/azuredevops/pipeline-java.yml @@ -0,0 +1,19 @@ + +trigger: +- main + +pool: + vmImage: ubuntu-latest + +steps: +- task: Gradle@2 + inputs: + workingDirectory: '' + gradleWrapperFile: 'gradlew' + gradleOptions: '-Xmx3072m' + javaHomeOption: 'JDKVersion' + jdkVersionOption: '1.8' + jdkArchitectureOption: 'x64' + publishJUnitResults: true + testResultsFiles: '**/TEST-*.xml' + tasks: 'build' \ No newline at end of file diff --git a/task_template.yml b/task_template.yml new file mode 100644 index 0000000..32cb7eb --- /dev/null +++ b/task_template.yml @@ -0,0 +1,20 @@ +parameters: + - name: modules + + +steps: + #- ${{ each module in parameters.modules }} + #- task: Docker@2 + # inputs: + # repository: ${{ parameters.image_name }} + # command: "buildAndPush" + # Dockerfile: ${{ module }}/Dockerfile + # buildContext: ${{ parameters.image_context }} + # arguments: ${{ parameters.arguments }} + # displayName: 'Docker build and push' + # condition: and(succeeded(), eq(variables['SHOULD_PUSH'], true)) + - bash: | + modules=(${{ parameters.modules }}) + for module in $modules;do + echo "Module impacted: $module" + done diff --git a/terraform/azure/Readme.md b/terraform/azure/Readme.md new file mode 100644 index 0000000..429fb40 --- /dev/null +++ b/terraform/azure/Readme.md @@ -0,0 +1 @@ +# Place for terraform code for Azure diff --git a/terraform/azure/main.tf b/terraform/azure/main.tf new file mode 100644 index 0000000..8a5c05c --- /dev/null +++ b/terraform/azure/main.tf @@ -0,0 +1,84 @@ +terraform { + + required_version = ">=0.12" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>2.0" + } + } + } + +resource "azurerm_resource_group" "resource_gp" { + name = "terraRG" + location = "southeastasia" + + tags = { + Owner = "Elvi" + } + +} + +variable "prefix" { + default = "lv" +} + + +resource "azurerm_virtual_network" "main" { + name = "${var.prefix}-network" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.resource_gp.location + resource_group_name = azurerm_resource_group.resource_gp.name +} + +resource "azurerm_subnet" "internal" { + name = "internal" + resource_group_name = azurerm_resource_group.resource_gp.name + virtual_network_name = azurerm_virtual_network.main.name + address_prefixes = ["10.0.2.0/24"] +} + +resource "azurerm_network_interface" "main" { + name = "${var.prefix}-nic" + location = azurerm_resource_group.resource_gp.location + resource_group_name = azurerm_resource_group.resource_gp.name + + ip_configuration { + name = "testconfiguration1" + subnet_id = azurerm_subnet.internal.id + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_virtual_machine" "main" { + name = "${var.prefix}-vm" + location = azurerm_resource_group.resource_gp.location + resource_group_name = azurerm_resource_group.resource_gp.name + network_interface_ids = [azurerm_network_interface.main.id] + vm_size = "Standard_DS1_v2" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + storage_os_disk { + name = "testdisk01" + caching = "ReadWrite" + create_option = "FromImage" + managed_disk_type = "Standard_LRS" + } + os_profile { + computer_name = "test-pc" + admin_username = "testadmin" + admin_password = "Password1234!" + } + os_profile_linux_config { + disable_password_authentication = false + } + tags = { + Owner = "Elvi" + } +} diff --git a/terraform/azure/variables.tf b/terraform/azure/variables.tf new file mode 100644 index 0000000..1c38b55 --- /dev/null +++ b/terraform/azure/variables.tf @@ -0,0 +1,24 @@ +provider "azurerm"{ + subscription_id = var.subscription_id + client_id = var.client_id + client_secret = var.client_secret + tenant_id = var.tenant_id + + features {} +} + +variable "subscription_id"{ + description = "Enter Subscription ID " +} + +variable "client_id"{ + description = "Enter Client ID " +} + +variable "client_secret"{ + description = "Enter Client Secret " +} + +variable "tenant_id"{ + description = "Enter Tenant ID" +} \ No newline at end of file