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

Dev #62

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Dev #62

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
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/__pycache__
**/venv
**/.pytest_cache
.coverage
.env
28 changes: 28 additions & 0 deletions .github/workflows/deploy-azure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy Azure Infrastructure

on:
push:
branches: [ main ]
workflow_dispatch:

permissions:
id-token: write
contents: read

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Login via Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Deploy Bicep
uses: azure/arm-deploy@v1
with:
resourceGroupName: 'BCSAI2024-DEVOPS-STUDENTS-B-DEV'
template: ./main.bicep
parameters: ./main.parameters.json
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.11-slim

# Install system dependencies
RUN apt-get update && apt-get install -y build-essential libpq-dev

# Set working directory
WORKDIR /app

# Copy requirements
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy application code
COPY . .

# Expose the application port
EXPOSE 5000

# Run the application
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "app:app"]
4 changes: 1 addition & 3 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os

from flask import (Flask, redirect, render_template, request,
send_from_directory, url_for)
from flask import Flask, redirect, render_template, request, send_from_directory, url_for

app = Flask(__name__)

Expand Down
53 changes: 53 additions & 0 deletions main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
param location string
param acrName string
param appServicePlanName string
param webAppName string
param containerRegistryImageName string
param containerRegistryImageVersion string

// Deploy ACR
module acr './modules/acr.bicep' = {
name: 'acrDeploy'
params: {
name: acrName
location: location
acrAdminUserEnabled: true
}
}

// Deploy App Service Plan
module appServicePlan './modules/app-service-plan.bicep' = {
name: 'appServicePlanDeploy'
params: {
name: appServicePlanName
location: location
sku: {
capacity: 1
family: 'B'
name: 'B1'
size: 'B1'
tier: 'Basic'
}
}
}

// Deploy Web App
module webApp './modules/web-app.bicep' = {
name: 'webAppDeploy'
params: {
name: webAppName
location: location
kind: 'app'
serverFarmResourceId: appServicePlan.outputs.id
siteConfig: {
linuxFxVersion: 'DOCKER|${acr.outputs.loginServer}/${containerRegistryImageName}:${containerRegistryImageVersion}'
appCommandLine: ''
}
appSettingsKeyValuePairs: {
WEBSITES_ENABLE_APP_SERVICE_STORAGE: 'false'
DOCKER_REGISTRY_SERVER_URL: 'https://${acr.outputs.loginServer}'
DOCKER_REGISTRY_SERVER_USERNAME: acr.outputs.adminUsername
DOCKER_REGISTRY_SERVER_PASSWORD: acr.outputs.adminPassword
}
}
}
24 changes: 24 additions & 0 deletions main.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"value": "westeurope"
},
"acrName": {
"value": "betroy-acr"
},
"appServicePlanName": {
"value": "betroy-asp"
},
"webAppName": {
"value": "betroy-web-app"
},
"containerRegistryImageName": {
"value": "myflaskapp"
},
"containerRegistryImageVersion": {
"value": "latest"
}
}
}
18 changes: 18 additions & 0 deletions modules/acr.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
param name string
param location string
param acrAdminUserEnabled bool = true

resource acr 'Microsoft.ContainerRegistry/registries@2023-07-01' = {
name: name
location: location
sku: {
name: 'Basic'
}
properties: {
adminUserEnabled: acrAdminUserEnabled
}
}

output loginServer string = acr.properties.loginServer
output adminUsername string = acr.name
output adminPassword string = listCredentials(acr.id, acr.apiVersion).passwords[0].value
15 changes: 15 additions & 0 deletions modules/app-service-plan.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
param name string
param location string
param sku object

resource appServicePlan 'Microsoft.Web/serverfarms@2022-09-01' = {
name: name
location: location
sku: sku
kind: 'Linux'
properties: {
reserved: true
}
}

output id string = appServicePlan.id
22 changes: 22 additions & 0 deletions modules/web-app.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
param name string
param location string
param kind string
param serverFarmResourceId string
param siteConfig object
param appSettingsKeyValuePairs object

resource webApp 'Microsoft.Web/sites@2022-09-01' = {
name: name
location: location
kind: kind
properties: {
serverFarmId: serverFarmResourceId
siteConfig: siteConfig
}
}

resource webAppSettings 'Microsoft.Web/sites/config@2022-09-01' = {
parent: webApp
name: 'appsettings'
properties: appSettingsKeyValuePairs
}