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

feat: onboarding the Containerized hello world tab with backend sample #1167

Merged
merged 14 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/hello-world-bot-with-tab @eriolchan @hund030
/hello-world-in-meeting @eriolchan @JerryYangKai
/hello-world-tab-codespaces @kimizhu @dooriya @qinezh
/hello-world-tab-docker @eriolchan @hund030 @Yimin-Jin
/hello-world-tab-with-backend @adashen @SLdragon @KennethBWSong
/hello-world-teams-tab-and-outlook-add-in @MSFT-yiz @jayzhang @HuihuiWu-Microsoft
/incoming-webhook-notification @kimizhu @dooriya @swatDong @XiaofuHuang
Expand Down
12 changes: 12 additions & 0 deletions hello-world-tab-docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
appPackage
assets
build
env
infra
node_modules
.gitignore
aad.manifest.json
*.md
compose*.yaml
Dockerfile
teamsapp*.yml
18 changes: 18 additions & 0 deletions hello-world-tab-docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# TeamsFx files
env/.env.*.user
env/.env.local
.DS_Store
build
appPackage/build
.deployment
.localConfigs

# dependencies
/node_modules

# testing
/coverage

# Dev tool directories
/devTools/
5 changes: 5 additions & 0 deletions hello-world-tab-docker/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"TeamsDevApp.ms-teams-vscode-extension"
]
}
73 changes: 73 additions & 0 deletions hello-world-tab-docker/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Remote in Teams (Edge)",
"type": "msedge",
"request": "launch",
"url": "https://teams.microsoft.com/l/app/${{TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}",
"presentation": {
"group": "group 1: Teams",
"order": 3
},
"internalConsoleOptions": "neverOpen"
},
{
"name": "Launch Remote in Teams (Chrome)",
"type": "chrome",
"request": "launch",
"url": "https://teams.microsoft.com/l/app/${{TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}",
"presentation": {
"group": "group 1: Teams",
"order": 3
},
"internalConsoleOptions": "neverOpen"
},
{
"name": "Attach to Frontend in Teams (Edge)",
"type": "msedge",
"request": "launch",
"url": "https://teams.microsoft.com/l/app/${{local:TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}",
"presentation": {
"group": "all",
"hidden": true
},
"postDebugTask": "Stop Application in Docker",
"internalConsoleOptions": "neverOpen"
},
{
"name": "Attach to Frontend in Teams (Chrome)",
"type": "chrome",
"request": "launch",
"url": "https://teams.microsoft.com/l/app/${{local:TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}",
"presentation": {
"group": "all",
"hidden": true
},
"postDebugTask": "Stop Application in Docker",
"internalConsoleOptions": "neverOpen"
}
],
"compounds": [
{
"name": "Debug in Teams (Edge)",
"configurations": ["Attach to Frontend in Teams (Edge)"],
"preLaunchTask": "Start Teams App in Docker",
"presentation": {
"group": "group 1: Teams",
"order": 1
},
"stopAll": true
},
{
"name": "Debug in Teams (Chrome)",
"configurations": ["Attach to Frontend in Teams (Chrome)"],
"preLaunchTask": "Start Teams App in Docker",
"presentation": {
"group": "group 1: Teams",
"order": 2
},
"stopAll": true
}
]
}
14 changes: 14 additions & 0 deletions hello-world-tab-docker/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"debug.onTaskErrors": "abort",
"json.schemas": [
{
"fileMatch": [
"/aad.*.json"
],
"schema": {}
}
],
"azureFunctions.stopFuncTaskPostDebug": false,
"azureFunctions.showProjectWarning": false,
"csharp.suppressDotnetRestoreNotification": true
}
60 changes: 60 additions & 0 deletions hello-world-tab-docker/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// This file is automatically generated by Teams Toolkit.
// The teamsfx tasks defined in this file require Teams Toolkit version >= 5.0.0.
// See https://aka.ms/teamsfx-tasks for details on how to customize each task.
{
"version": "2.0.0",
"tasks": [
{
"label": "Validate Docker prerequisites",
"type": "teamsfx",
"command": "debug-check-prerequisites",
"args": {
"prerequisites": [
"m365Account", // Sign-in prompt for Microsoft 365 account, then validate if the account enables the sideloading permission.
"portOccupancy" // Validate available ports to ensure those debug ones are not occupied.
],
"portOccupancy": [
53000, // tab service port
7071, // backend service port
9229 // backend inspector port for Node.js debugger
]
}
},
{
"label": "Start Teams App in Docker",
"dependsOn": [
"Validate Docker prerequisites",
"Provision",
"Start Application in Docker"
],
"dependsOrder": "sequence"
},
{
// Create the debug resources.
// See https://aka.ms/teamsfx-tasks/provision to know the details and how to customize the args.
"label": "Provision",
"type": "teamsfx",
"command": "provision",
"args": {
"env": "local"
}
},
{
"label": "Stop Application in Docker",
"type": "shell",
"command": "docker compose -f ${workspaceFolder}/docker-compose.yml down",
"isBackground": true
},
{
"label": "Start Application in Docker",
"type": "shell",
"command": "docker compose -f ${workspaceFolder}/docker-compose.yml up -d",
"isBackground": true,
"options": {
"env": {
"HOME": "${userHome}"
}
}
}
]
}
14 changes: 14 additions & 0 deletions hello-world-tab-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:18.18.0 AS development

WORKDIR /app
COPY package*.json /app/
RUN npm install
COPY . /app/

CMD ["npm", "start"]

FROM development AS build
RUN npm run build

FROM nginx:1.21.3-alpine AS production
COPY --from=build /app/build /usr/share/nginx/html
108 changes: 108 additions & 0 deletions hello-world-tab-docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
page_type: sample
languages:
- typescript
products:
- office-teams
name: Containerized Tab App with Azure Backend
urlFragment: officedev-teamsfx-samples-tab-hello-world-tab-docker
description: A containerized Hello World app of Microsoft Teams Tab app which has a backend service.
extensions:
createdDate: "2024-02-27"
---
# Getting Started with Hello World Tab with Backend Sample in Docker

Microsoft Teams supports the ability to run web-based UI inside "custom tabs" that users can install either for just themselves (personal tabs) or within a team or group chat context.

Hello World Tab with Backend shows you how to build a tab app with an Azure Function as backend, how to get user login information with SSO and how to call Azure Function from frontend tab.

![Hello World Tab](assets/sampleDemo.gif)

> Note: This sample will only provision [single tenant](https://learn.microsoft.com/azure/active-directory/develop/single-and-multi-tenant-apps#who-can-sign-in-to-your-app) Azure Active Directory app. For multi-tenant support, please refer to this [wiki](https://aka.ms/teamsfx-multi-tenant).

## This sample illustrates

- How to use Teams Toolkit to create a Teams tab app.
- How to use TeamsFx SDK to call Azure Functions.
- How to use TeamsFx SDK in Azure Function to call Graph to get user info.
- How to develop Teams tab app in Docker.

## Prerequisites

- [Docker Engine](https://docs.docker.com/engine/install/)
- A Microsoft 365 account. If you do not have Microsoft 365 account, apply one from [Microsoft 365 developer program](https://developer.microsoft.com/en-us/microsoft-365/dev-program)
- [Teams Toolkit Visual Studio Code Extension](https://aka.ms/teams-toolkit) version 5.0.0 and higher or [TeamsFx CLI](https://aka.ms/teamsfx-cli)
- [Azure Cli](https://learn.microsoft.com/cli/azure/install-azure-cli) for Azure Container Apps deployment

# Note
- This sample has adopted [On-Behalf-Of Flow](https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow) to implement SSO.

- This sample uses Azure Function as middle-tier service, and make authenticated requests to call Graph from Azure Function.

- Due to system webview limitations, users in the tenant with conditional access policies applied cannot consent permissions when conduct an OAuth flow within the Teams mobile clients, it would show error: "xxx requires you to secure this device...".

## Containerization of Teams App

Teams applications can be developed and run locally using containerization, which provides a consistent and isolated environment for testing and deployment. Containerizing your Teams app makes it easier to manage dependencies, scale efficiently, and maintain your app in production. Below are steps and references to help you containerize your Teams app.

### How to containerize

This sample demonstrate how to containerize a Teams App and integrate the Docker container into Teams Toolkit development lifecycle, which can serve as reference for your containerization process.

- **Write a Dockerfile**: Create a Dockerfile that specifies the build instructions for your container image. Refer to this [Dockerfile example](./Dockerfile)

- **Write a Compose File**: Create a Docker Compose file that defines the services, networks and volumes, expecially when there are multiple containers. Refer to this [Docker Compose file example](./docker-compose.yml)

- **Configure Debugging**: Configure `launch.json` and `tasks.json` to run Docker locally for debugging. Refer to this [VS Code launch.json example](./.vscode/launch.json) and [VS Code tasks.json example](./.vscode/tasks.json)

- **Provision Infrastructure**: Automate the provisioning of Azure Container Apps and Azure Container Registry using Bicep templates. Refer to this [Azure Bicep example](./infra/azure.bicep).

- **Build and Deploy to ACA**: Build the Docker image and push it to Azure Container Registry using Docker CLI. Deploy the image to Azure Container Apps using Azure CLI. Refer to the deployment scripts in this [teamsapp.yml example](./teamsapp.yml).

## Minimal path to awesome

### Run the app locally

- From VS Code:
1. hit `F5` to start debugging. Alternatively open the `Run and Debug Activity` Panel and select `Debug in Teams (Edge)` or `Debug in Teams (Chrome)`.

- From TeamsFx CLI:
1. Run command: `teamsapp provision --env local` .
1. Run command: `docker compose -f ./docker-compose.yml up -d` .
1. Run command: `teamsapp preview --open-only` .

### Deploy the app to Azure

- From VS Code:
1. Sign into Azure by clicking the `Sign in to Azure` under the `ACCOUNTS` section from sidebar.
1. Click `Provision` from `LIFECYCLE` section or open the command palette and select: `Teams: Provision` .
1. Login Azure CLI with commands: `az login` and `az account set -s <subscription-id>` .
1. Click `Deploy` or open the command palette and select: `Teams: Deploy` .

- From TeamsFx CLI:
1. Run command: `teamsapp auth login azure` .
1. Run command: `teamsapp provision --env dev` .
1. Run command: `az login` .
1. Run command: `teamsapp deploy --env dev` .

### Preview the app in Teams

- From VS Code:
1. Open the `Run and Debug Activity` Panel. Select `Launch Remote (Edge)` or `Launch Remote (Chrome)` from the launch configuration drop-down.

- From TeamsFx CLI:
1. Run command: `teamsapp preview --env dev`.

## Further reading

- [Azure Container Apps overview](https://learn.microsoft.com/azure/container-apps/overview)
- [Tutorial: Communication between microservices in Azure Container Apps](https://learn.microsoft.com/azure/container-apps/communicate-between-microservices)

## Version History

|Date| Author| Comments|
|---|---|---|
|Feb 27, 2024| hund030 | onboard sample in Teams Toolkit V5.0.0|

## Feedback
We really appreciate your feedback! If you encounter any issue or error, please report issues to us following the [Supporting Guide](https://github.com/OfficeDev/TeamsFx-Samples/blob/dev/SUPPORT.md). Meanwhile you can make [recording](https://aka.ms/teamsfx-record) of your journey with our product, they really make the product better. Thank you!
Loading
Loading