Skip to content

Commit

Permalink
First draft of Actions workflows and Dockerfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
feaselkl committed Aug 26, 2024
1 parent feaabf2 commit 70740b5
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/.github/workflows/api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: API Deployment

env:
registryName: {your_registry_name}.azurecr.io
repositoryName: techexcel/csapi
dockerFolderPath: ./src/ContosoSuitesWebAPI
tag: ${{github.run_number}}

on:
push:
branches: [ main ]
paths: src/ContosoSuitesWebAPI/**
pull_request:
branches: [ main ]
paths: src/ContosoSuitesWebAPI/**
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0

- name: Restore dependencies
run: dotnet restore ./src/ContosoSuitesWebAPI/ContosoSuitesWebAPI.csproj
- name: Build
run: dotnet build --no-restore ./src/ContosoSuitesWebAPI/ContosoSuitesWebAPI.csproj

dockerBuildPush:
runs-on: ubuntu-latest
needs: build

steps:
- uses: actions/checkout@v3

- name: Docker Login
# You may pin to the exact commit or the version.
# uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
uses: docker/[email protected]
with:
# Server address of Docker registry. If not set then will default to Docker Hub
registry: ${{ secrets.ACR_LOGIN_SERVER }}
# Username used to log against the Docker registry
username: ${{ secrets.ACR_USERNAME }}
# Password or personal access token used to log against the Docker registry
password: ${{ secrets.ACR_PASSWORD }}
# Log out from the Docker registry at the end of a job
logout: true

- name: Docker Build
run: docker build -t $registryName/$repositoryName:$tag --build-arg build_version=$tag $dockerFolderPath

- name: Docker Push
run: docker push $registryName/$repositoryName:$tag

deploy-to-prod:

runs-on: ubuntu-latest
environment:
name: prod
url: https://{your_prefix}-api.azurewebsites.net/

steps:
- uses: actions/checkout@v3

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

- uses: azure/webapps-deploy@v2
with:
app-name: '{your_prefix}-api'
images: {your_registry_name}.azurecr.io/techexcel/csapi:${{github.run_number}}
77 changes: 77 additions & 0 deletions src/.github/workflows/dashboard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Dashboard Deployment

env:
registryName: {your_registry_name}.azurecr.io
repositoryName: techexcel/csdash
dockerFolderPath: ./src/ContosoSuitesDashboard
tag: ${{github.run_number}}

on:
push:
branches: [ main ]
paths: src/ContosoSuitesDashboard/**
pull_request:
branches: [ main ]
paths: src/ContosoSuitesDashboard/**
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
buildSecretsFile:

runs-on: ubuntu-latest

steps:

# TODO: Add steps here to create the secrets file from Github Secrets
- name: Create Secrets File
run: echo "$STREAMLIT_SECRETS >> .streamlit/secrets.toml"
shell: bash
env:
STREAMLIT_SECRETS: ${{ secrets.STREAMLIT_SECRETS }}

dockerBuildPush:
runs-on: ubuntu-latest
needs: buildSecretsFile

steps:
- uses: actions/checkout@v3

- name: Docker Login
# You may pin to the exact commit or the version.
# uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
uses: docker/[email protected]
with:
# Server address of Docker registry. If not set then will default to Docker Hub
registry: ${{ secrets.ACR_LOGIN_SERVER }}
# Username used to log against the Docker registry
username: ${{ secrets.ACR_USERNAME }}
# Password or personal access token used to log against the Docker registry
password: ${{ secrets.ACR_PASSWORD }}
# Log out from the Docker registry at the end of a job
logout: true

- name: Docker Build
run: docker build -t $registryName/$repositoryName:$tag --build-arg build_version=$tag $dockerFolderPath

- name: Docker Push
run: docker push $registryName/$repositoryName:$tag

deploy-to-prod:

runs-on: ubuntu-latest
environment:
name: prod
url: https://{your_prefix}-dash.azurewebsites.net/

steps:
- uses: actions/checkout@v3

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

- uses: azure/webapps-deploy@v2
with:
app-name: '{your_prefix}-dash'
images: {your_registry_name}.azurecr.io/techexcel/csdash:${{github.run_number}}
18 changes: 18 additions & 0 deletions src/ContosoSuitesDashboard/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM python:3.12-slim
WORKDIR /app
RUN apt-get update && apt-get install -y \
build-essential \
curl \
software-properties-common \
git \
&& rm -rf /var/lib/apt/lists/*
COPY . /app
RUN pip3 install -r requirements.txt
# You must have a secrets.toml file in .streamlit.
# This file should contain the following sections and keys:
# aoai: endpoint, key, deployment_name
# search: endpoint, key, index_name
# speech: key, region
COPY ./.streamlit/ ./.streamlit/
EXPOSE 8501
ENTRYPOINT ["streamlit", "run", "Index.py", "--server.port=8501", "--server.address=0.0.0.0"]
18 changes: 18 additions & 0 deletions src/ContosoSuitesWebAPI/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build-env /app/out .
# Default ASP.NET port changed with .NET 8.0
ENV ASPNETCORE_HTTP_PORTS=80
ENTRYPOINT ["dotnet", "ContosoSuitesWebAPI.dll"]

0 comments on commit 70740b5

Please sign in to comment.