Terraform

This commit is contained in:
Martynas Petuška 2021-03-21 19:02:51 +00:00
parent ccea676b77
commit e1b11c20a2
9 changed files with 276 additions and 122 deletions

14
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/.github/workflows"
schedule:
interval: "daily"
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "terraform"
directory: "/infra"
schedule:
interval: "daily"

95
.github/workflows/Release.yml vendored Normal file
View File

@ -0,0 +1,95 @@
name: Release
on:
workflow_dispatch:
release:
types: [ created ]
jobs:
build:
name: Build App
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Restore Gradle cache
id: cache
uses: actions/cache@v2.1.4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- uses: actions/setup-java@v1.4.3
with:
java-version: 1.8
- name: Build Web App
run: ./gradlew :web-app:build
- name: Upload Static Web App Artifact
uses: actions/upload-artifact@v2
id: upload
with:
path: web-app/build/distributions
name: static-web-app
if-no-files-found: error
deploy-Infrastructure:
runs-on: ubuntu-latest
name: Deploy Main Infrastructure
needs: [ build ]
env:
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USER }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
ARM_ACCESS_KEY: ${{ secrets.ARM_ACCESS_KEY }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Terraform environment
uses: little-core-labs/install-terraform@v2.0.0
with:
version: 0.14.5
- name: Terraform init
run: terraform init
working-directory: infra
- name: Terraform apply
run: terraform apply -auto-approve
working-directory: infra
env:
TF_VAR_docker_registry_username: ${{ secrets.GH_PKG_USER }}
TF_VAR_docker_registry_password: ${{ secrets.GH_PKG_PASSWORD }}
TF_VAR_api_admin_user: ${{ secrets.API_ADMIN_USER }}
TF_VAR_api_admin_password: ${{ secrets.API_ADMIN_PASSWORD }}
TF_VAR_cors_anywhere_allow_list: ""
TF_VAR_cors_anywhere_rate_limit: ""
deploy-StaticWebApp:
runs-on: ubuntu-latest
name: Deploy Static Web App
needs: [ build ]
steps:
- name: Download Static Web App Artifact
uses: actions/download-artifact@v2
with:
name: static-web-app
path: dist/
- name: Deploy
uses: JamesIves/github-pages-deploy-action@4.1.0
with:
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: dist/ # The folder the action should deploy.
CLEAN: true # Automatically remove deleted files from the deploy branch
# - name: Deploy Azure Static Web App
# uses: Azure/static-web-apps-deploy@v0.0.1-preview
# with:
# azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_AMBITIOUS_WATER_0BC116E03 }}
# repo_token: ${{ github.token }} # Used for Github integrations (i.e. PR comments)
# action: "upload"
# ###### Repository/Build Configurations - These values can be configured to match you app requirements. ######
# # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
# app_location: "/dist"
# ###### End of Repository/Build Configurations ######

35
.github/workflows/tf-refresh.yml vendored Normal file
View File

@ -0,0 +1,35 @@
name: Refresh Terraform State
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 0'
jobs:
refresh-Infrastructure:
runs-on: ubuntu-latest
name: Refresh Main Infrastructure
env:
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USER }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
ARM_ACCESS_KEY: ${{ secrets.ARM_ACCESS_KEY }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Terraform environment
uses: little-core-labs/install-terraform@v2.0.0
with:
version: 0.14.5
- name: Terraform init
run: terraform init
working-directory: infra
- name: Terraform refresh
run: terraform refresh
working-directory: infra
env:
TF_VAR_docker_registry_username: ${{ secrets.GH_PKG_USER }}
TF_VAR_docker_registry_password: ${{ secrets.GH_PKG_PASSWORD }}

126
.gitignore vendored
View File

@ -1,122 +1,8 @@
/fuzzywuzzy/app/build/ .idea/
/desktop/build/classes/kotlin/jvm/main/META-INF/desktop.kotlin_module local.properties
/desktop/build/classes/kotlin/jvm/main/ComposableSingletons$MainKt$lambda-1$1$1.class
/desktop/build/classes/kotlin/jvm/main/ComposableSingletons$MainKt$lambda-1$1.class
/desktop/build/classes/kotlin/jvm/main/ComposableSingletons$MainKt$lambda-2$1.class
/desktop/build/classes/kotlin/jvm/main/ComposableSingletons$MainKt$lambda-3$1.class
/desktop/build/classes/kotlin/jvm/main/ComposableSingletons$MainKt.class
/desktop/build/classes/kotlin/jvm/main/MainKt$spotiFlyerRoot$1.class
/desktop/build/classes/kotlin/jvm/main/MainKt.class
/desktop/build/processedResources/jvm/main/drawable/ic_arrow.xml
/desktop/build/processedResources/jvm/main/drawable/ic_download_arrow.xml
/desktop/build/processedResources/jvm/main/drawable/ic_error.xml
/desktop/build/processedResources/jvm/main/drawable/ic_gaana.xml
/desktop/build/processedResources/jvm/main/drawable/ic_github.xml
/desktop/build/processedResources/jvm/main/drawable/ic_heart.xml
/desktop/build/processedResources/jvm/main/drawable/ic_history.xml
/desktop/build/processedResources/jvm/main/drawable/ic_instagram.xml
/desktop/build/processedResources/jvm/main/drawable/ic_linkedin.xml
/desktop/build/processedResources/jvm/main/drawable/ic_mug.xml
/desktop/build/processedResources/jvm/main/drawable/ic_musicplaceholder.xml
/desktop/build/processedResources/jvm/main/drawable/ic_refreshgradient.xml
/desktop/build/processedResources/jvm/main/drawable/ic_round_cancel_24.xml
/desktop/build/processedResources/jvm/main/drawable/ic_share_open.xml
/desktop/build/processedResources/jvm/main/drawable/ic_song_placeholder.xml
/desktop/build/processedResources/jvm/main/drawable/ic_spotiflyer_logo.xml
/desktop/build/processedResources/jvm/main/drawable/ic_spotify_logo.xml
/desktop/build/processedResources/jvm/main/drawable/ic_tick.xml
/desktop/build/processedResources/jvm/main/drawable/ic_youtube.xml
/desktop/build/processedResources/jvm/main/drawable/ic_youtube_music_logo.xml
/desktop/build/processedResources/jvm/main/drawable/music.xml
/desktop/build/compose/tmp/createRuntimeImage.args.txt
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/inputs/source-to-output.tab
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/inputs/source-to-output.tab.keystream
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/inputs/source-to-output.tab.keystream.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/inputs/source-to-output.tab.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/inputs/source-to-output.tab.values.at
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/inputs/source-to-output.tab_i
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/inputs/source-to-output.tab_i.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/internal-name-to-source.tab
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/package-parts.tab
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/package-parts.tab.keystream
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/package-parts.tab.keystream.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/package-parts.tab.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/package-parts.tab.values.at
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/package-parts.tab_i
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/package-parts.tab_i.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/proto.tab
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/proto.tab.keystream
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/proto.tab.keystream.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/proto.tab.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/proto.tab.values.at
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/proto.tab_i
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/proto.tab_i.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/source-to-classes.tab
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/source-to-classes.tab.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/source-to-classes.tab_i
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/jvm/kotlin/source-to-classes.tab_i.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/counters.tab
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/file-to-id.tab
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/file-to-id.tab.keystream
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/file-to-id.tab.keystream.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/file-to-id.tab.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/file-to-id.tab.values.at
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/file-to-id.tab_i
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/file-to-id.tab_i.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/id-to-file.tab
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/id-to-file.tab.keystream
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/id-to-file.tab.keystream.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/id-to-file.tab.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/id-to-file.tab.values.at
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/lookups.tab
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/lookups.tab.keystream
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/lookups.tab.keystream.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/lookups.tab.len
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/lookups.tab.values.at
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/lookups.tab_i
/desktop/build/kotlin/compileKotlinJvm/caches-jvm/lookups/lookups.tab_i.len
/desktop/build/kotlin/compileKotlinJvm/build-history.bin
/desktop/build/kotlin/compileKotlinJvm/last-build.bin
/desktop/build/libs/desktop-jvm-2.2.jar
/desktop/build/libs/desktop-metadata-2.2.jar
/desktop/build/libs/desktop-metadata-2.2-sources.jar
/desktop/build/tmp/jvmJar/MANIFEST.MF
/desktop/build/tmp/metadataJar/MANIFEST.MF
/desktop/build/tmp/metadataSourcesJar/MANIFEST.MF
/desktop/build/tmp/packageUberJarForCurrentOS/MANIFEST.MF
/common/dependency-injection/build/classes/kotlin/desktop/main/
/common/dependency-injection/build/
/common/database/build/generated/sqldelight/code/Database/com/shabinder/
/.gradle/
/.idea/
/local.properties
/android/build/
/buildSrc/build/pluginUnderTestMetadata/
/common/compose-ui/build/classes/kotlin/desktop/main/
/common/data-models/build/classes/kotlin/desktop/main/
/common/data-models/build/
/common/database/build/classes/kotlin/desktop/main/
/common/database/build/
/build/
/common/compose-ui/build/
/buildSrc/.gradle/
/buildSrc/build/
/buildSrc/buildSrc/.gradle/
/buildSrc/buildSrc/build/
/desktop/build/
/common/compose/build/
/common/list/build/
/common/main/build/
/common/root/build/
/android/release/ /android/release/
/android/google-services.json /android/google-services.json
/web-app/build/ build/
.gradle/
terraform.tfvars
.terraform/

View File

@ -38,8 +38,8 @@ kotlin.code.style=official
org.gradle.parallel=true org.gradle.parallel=true
org.gradle.caching=true org.gradle.caching=true
kotlin.native.disableCompilerDaemon=true kotlin.native.disableCompilerDaemon=true
#kotlin.code.style=official kotlin.mpp.stability.nowarn=true
#android.useAndroidX=true #android.useAndroidX=true
#kotlin.mpp.enableGranularSourceSetsMetadata=true #kotlin.mpp.enableGranularSourceSetsMetadata=true
#kotlin.native.enableDependencyPropagation=false #kotlin.native.enableDependencyPropagation=false
#org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 #org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

20
infra/.terraform.lock.hcl Executable file
View File

@ -0,0 +1,20 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/azurerm" {
version = "2.52.0"
hashes = [
"h1:bYwfAgIZFgbGVGYjnZ0OO+RumXn6UDNl2VmIm5gi8tI=",
"zh:1ee2dd8215919001736ae27473844c80a04ebbd56ddd12eca7f45aab6cda2274",
"zh:26791137ce5e7ea088caf75321aefb19f1ad5eb63dcc736342c99866a1b3af0e",
"zh:4903fda8700381ae7b91dc0c1e2fbea6ab63f56f14a09f7ba73c914d3f9d02b3",
"zh:5b6e49c9878d8586cbe38eae5188fb0a92319a5fdb33f51fe27ac50a7a8aa1f6",
"zh:64d5707955e73655e6aefaa6f9abce2fedd7e068cbe71fcc84a676263f39ef3e",
"zh:9646bef60395ceca137eea5bf87aa3a5b68a45e1018a6fa600a6d497a112b8ce",
"zh:9e0e716e08c433974c1b48084117762f59e5323d5de62b10cde53dec6e0bd6ae",
"zh:cc348e88922a82bd3ab6bab590735949f219fee9c021214861fed7c65546ec86",
"zh:d09368d44ee2f759ba3427c391e21aed2dda50cc39f079dea3160e5aad2f0ab0",
"zh:df88a810a6867d96d4452a0eb74e835e3c7c55522e53ee1d7a32af2e91e72abf",
"zh:f8fee4ec974e31b8eeaeb95dd1d844e58fdd121dbd37e2130586f61ed9a83ac2",
]
}

68
infra/main.tf Normal file
View File

@ -0,0 +1,68 @@
terraform {
backend "artifactory" {
// -backend-config="username=xxx@xxx.com" \
// -backend-config="password=xxxxxx" \
url = "https://spotiflyer.jfrog.io/artifactory"
repo = "terraform-state"
subpath = "SpotiFlyer"
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "main" {
location = "westeurope"
name = "SpotiFlyer"
}
resource "azurerm_application_insights" "main" {
name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
application_type = "java"
}
resource "azurerm_app_service_plan" "main" {
location = azurerm_resource_group.main.location
name = azurerm_resource_group.main.name
resource_group_name = azurerm_resource_group.main.name
kind = "Linux"
reserved = true
sku {
tier = "Free"
size = "F1"
}
}
resource "azurerm_app_service" "main" {
resource_group_name = azurerm_app_service_plan.main.resource_group_name
app_service_plan_id = azurerm_app_service_plan.main.id
location = azurerm_app_service_plan.main.location
name = azurerm_app_service_plan.main.name
https_only = true
site_config {
use_32_bit_worker_process = true
app_command_line = ""
linux_fx_version = "DOCKER|${var.docker_image_tag}"
http2_enabled = true
cors {
allowed_origins = ["*"]
}
}
app_settings = {
WEBSITES_ENABLE_APP_SERVICE_STORAGE = false
DOCKER_REGISTRY_SERVER_URL = var.docker_registry
DOCKER_REGISTRY_SERVER_USERNAME = var.docker_registry_username
DOCKER_REGISTRY_SERVER_PASSWORD = var.docker_registry_password
AZURE_MONITOR_INSTRUMENTATION_KEY = azurerm_application_insights.main.instrumentation_key
APPINSIGHTS_INSTRUMENTATIONKEY = azurerm_application_insights.main.instrumentation_key
APPINSIGHTS_PROFILERFEATURE_VERSION = "1.0.0"
WEBSITE_HTTPLOGGING_RETENTION_DAYS = "35"
CORSANYWHERE_ALLOWLIST = var.cors_anywhere_allow_list
CORSANYWHERE_RATELIMIT = var.cors_anywhere_rate_limit
}
}

7
infra/outputs.tf Normal file
View File

@ -0,0 +1,7 @@
output "app_service_name" {
value = azurerm_app_service.main.name
}
output "app_service_default_hostname" {
value = "https://${azurerm_app_service.main.default_site_hostname}"
}

29
infra/variables.tf Normal file
View File

@ -0,0 +1,29 @@
variable "docker_registry" {
type = string
default = "https://docker.pkg.github.com"
}
variable "docker_registry_username" {
type = string
}
variable "docker_registry_password" {
type = string
sensitive = true
}
variable "docker_image_tag" {
type = string
default = "docker.pkg.github.com/shabinder/cors-anywhere/server:latest"
}
variable "cors_anywhere_allow_list" {
type = string
default = ""
}
variable "cors_anywhere_rate_limit" {
type = string
default = ""
}