diff --git a/src/.github/workflows/api.yml b/src/.github/workflows/api.yml new file mode 100644 index 000000000..09f84198c --- /dev/null +++ b/src/.github/workflows/api.yml @@ -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/login-action@v1.9.0 + 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}} diff --git a/src/.github/workflows/dashboard.yml b/src/.github/workflows/dashboard.yml new file mode 100644 index 000000000..29f91f040 --- /dev/null +++ b/src/.github/workflows/dashboard.yml @@ -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/login-action@v1.9.0 + 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}} diff --git a/src/ContosoSuitesDashboard/Dockerfile b/src/ContosoSuitesDashboard/Dockerfile new file mode 100644 index 000000000..9c069825d --- /dev/null +++ b/src/ContosoSuitesDashboard/Dockerfile @@ -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"] \ No newline at end of file diff --git a/src/ContosoSuitesWebAPI/Dockerfile b/src/ContosoSuitesWebAPI/Dockerfile new file mode 100644 index 000000000..9a4d185ce --- /dev/null +++ b/src/ContosoSuitesWebAPI/Dockerfile @@ -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"] \ No newline at end of file