Skip to content

Commit b752fe3

Browse files
committed
updates to docs and deployments
1 parent 2752cb8 commit b752fe3

File tree

11 files changed

+144
-158
lines changed

11 files changed

+144
-158
lines changed

.github/workflows/playwright.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
run: |
6565
docker run --rm --name playwright \
6666
-v $(pwd)/test-results-docker:/test-results \
67+
-e NUXT_SESSION_PASSWORD=foo-foo-foo-foo-foo-foo-foo-foo-foo-foo-foo-foo \
6768
app:pw
6869
- uses: actions/upload-artifact@v4
6970
if: always()

DEPLOYMENT.md

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ There are a few ways to deploy the Copilot Metrics Viewer, depending on the type
44

55
The app runs in a Docker container, so it can be deployed anywhere containers are hosted (AWS, GCP, Azure, Kubernetes, etc.).
66

7-
## Authentication to GitHub
7+
## Deployment options
8+
9+
Review available [Nuxt Deployment Options](https://nuxt.com/deploy).
10+
11+
>[!WARNING]
12+
> Copilot Metrics Viewer requires a backend, hence it cannot be deployed as a purely static web app.
13+
14+
## Authentication with GitHub
815

916
The Metrics Viewer can be integrated with GitHub application authentication, which authenticates the user and verifies their permissions to view the metrics. This option is recommended since it doesn't use Personal Access Tokens. The downside of using a GitHub application is that it can only authorize users to view metrics at the organization level (no support for Enterprise).
1017

18+
For Enterprise level authentication review [Github OAuth Apps](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/differences-between-github-apps-and-oauth-apps).
19+
1120
With a Personal Access Token, user credentials are not verified, and the application simply renders Copilot metrics fetched using the PAT stored in the backend.
1221

1322
## Authentication for Copilot Metrics Viewer
@@ -27,7 +36,7 @@ The simplest way to deploy is to use the "one-click" option that creates resourc
2736

2837
![Azure ARM Deployment](./azure-deploy/arm-deployment.png)
2938

30-
Application will use a pre-built docker image hosted in GitHub registry: `ghcr.io/github-copilot-resources/copilot-metrics-viewer-with-proxy`.
39+
Application will use a pre-built docker image hosted in GitHub registry: `ghcr.io/github-copilot-resources/copilot-metrics-viewer`.
3140

3241
**Prerequisites:** Contributor permission to a resource group in Azure and a subscription with the `Microsoft.App` resource provider enabled.
3342

@@ -89,14 +98,13 @@ The deployment creates:
8998
Before running `azd up`, configure GitHub variables:
9099
91100
```bash
92-
azd env set VUE_APP_SCOPE <organization/enterprise>
101+
azd env set NUXT_PUBLIC_SCOPE <organization/enterprise>
93102
# when using organization
94-
azd env set VUE_APP_GITHUB_ORG <org name>
103+
azd env set NUXT_PUBLIC_GITHUB_ORG <org name>
95104
# when using enterprise
96-
azd env set VUE_APP_GITHUB_ENT <ent name>
97-
azd env set VUE_APP_GITHUB_API /api/github
98-
azd env set GITHUB_CLIENT_ID <client id>
99-
azd env set GITHUB_CLIENT_SECRET <client secret for the GH App>
105+
azd env set NUXT_PUBLIC_GITHUB_ENT <ent name>
106+
azd env set NUXT_OAUTH_GITHUB_CLIENT_ID <client id>
107+
azd env set NUXT_OAUTH_GITHUB_CLIENT_SECRET <client secret for the GH App>
100108
```
101109

102110
## Scenario 3: Deploying the container
@@ -107,37 +115,34 @@ For GitHub App:
107115

108116
```bash
109117
docker run -it --rm -p 3000:3000 \
110-
-e VUE_APP_SCOPE=organization \
111-
-e VUE_APP_GITHUB_API=/api/github \
112-
-e VUE_APP_GITHUB_ORG=<org name> \
113-
-e GITHUB_CLIENT_ID=<client id> \
114-
-e GITHUB_CLIENT_SECRET=<client secret for the GH App> \
115-
-e SESSION_SECRET=<random string> \
116-
ghcr.io/github-copilot-resources/copilot-metrics-viewer-with-proxy
118+
-e NUXT_PUBLIC_SCOPE=organization \
119+
-e NUXT_PUBLIC_GITHUB_ORG=<org name> \
120+
-e NUXT_OAUTH_GITHUB_CLIENT_ID=<client id> \
121+
-e NUXT_OAUTH_GITHUB_CLIENT_SECRET=<client secret for the GH App> \
122+
-e NUXT_SESSION_PASSWORD=<random string - min 32 characters> \
123+
ghcr.io/github-copilot-resources/copilot-metrics-viewer
117124
```
118125

119126
or with PAT token and enterprise:
120127

121128
```bash
122129
docker run -it --rm -p 3000:3000 \
123-
-e VUE_APP_SCOPE=enterprise \
124-
-e VUE_APP_GITHUB_API=/api/github \
125-
-e VUE_APP_GITHUB_ENT=<enterprise name> \
126-
-e VUE_APP_GITHUB_TOKEN=<github PAT> \
127-
-e SESSION_SECRET=<random string> \
128-
ghcr.io/github-copilot-resources/copilot-metrics-viewer-with-proxy
130+
-e NUXT_PUBLIC_SCOPE=enterprise \
131+
-e NUXT_PUBLIC_GITHUB_ENT=<enterprise name> \
132+
-e NUXT_GITHUB_TOKEN=<github PAT> \
133+
-e NUXT_SESSION_PASSWORD=<random string - min 32 characters> \
134+
ghcr.io/github-copilot-resources/copilot-metrics-viewer
129135
```
130136

131137
or with PAT token and organization:
132138

133139
```bash
134140
docker run -it --rm -p 3000:3000 \
135-
-e VUE_APP_SCOPE=organization \
136-
-e VUE_APP_GITHUB_API=/api/github \
137-
-e VUE_APP_GITHUB_ORG=<org name> \
138-
-e VUE_APP_GITHUB_TOKEN=<github PAT> \
139-
-e SESSION_SECRET=<random string> \
140-
ghcr.io/github-copilot-resources/copilot-metrics-viewer-with-proxy
141+
-e NUXT_PUBLIC_SCOPE=organization \
142+
-e NUXT_PUBLIC_GITHUB_ORG=<org name> \
143+
-e NUXT_GITHUB_TOKEN=<github PAT> \
144+
-e NUXT_SESSION_PASSWORD=<random string - min 32 characters> \
145+
ghcr.io/github-copilot-resources/copilot-metrics-viewer
141146
```
142147

143148
## Github App Registration

Dockerfile

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,29 @@ WORKDIR /app
2323
COPY --chown=1000:1000 --from=build-stage /app/.output /app
2424

2525
# Expose the port your API will run on
26-
EXPOSE 3000
26+
EXPOSE 80
27+
28+
# Set port to 80 for backwards compatibility
29+
ENV NITRO_PORT=80
30+
31+
# Re-map the environment variables for the Vue.js app for backwards compatibility
32+
RUN echo '#!/bin/sh' > /entrypoint.sh && \
33+
echo 'export NUXT_PUBLIC_IS_DATA_MOCKED=${NUXT_PUBLIC_IS_DATA_MOCKED:-$VUE_APP_MOCKED_DATA}' >> /entrypoint.sh && \
34+
echo 'export NUXT_PUBLIC_SCOPE=${NUXT_PUBLIC_SCOPE:-$VUE_APP_SCOPE}' >> /entrypoint.sh && \
35+
echo 'export NUXT_PUBLIC_GITHUB_ORG=${NUXT_PUBLIC_GITHUB_ORG:-$VUE_APP_GITHUB_ORG}' >> /entrypoint.sh && \
36+
echo 'export NUXT_PUBLIC_GITHUB_ENT=${NUXT_PUBLIC_GITHUB_ENT:-$VUE_APP_GITHUB_ENT}' >> /entrypoint.sh && \
37+
echo 'export NUXT_PUBLIC_GITHUB_TEAM=${NUXT_PUBLIC_GITHUB_TEAM:-$VUE_APP_GITHUB_TEAM}' >> /entrypoint.sh && \
38+
echo 'export NUXT_GITHUB_TOKEN=${NUXT_GITHUB_TOKEN:-$VUE_APP_GITHUB_TOKEN}' >> /entrypoint.sh && \
39+
echo 'export NUXT_SESSION_PASSWORD=${NUXT_SESSION_PASSWORD:-$SESSION_SECRET}' >> /entrypoint.sh && \
40+
echo 'export NUXT_OAUTH_GITHUB_CLIENT_ID=${NUXT_OAUTH_GITHUB_CLIENT_ID:-$GITHUB_CLIENT_ID}' >> /entrypoint.sh && \
41+
echo 'export NUXT_OAUTH_GITHUB_CLIENT_SECRET=${NUXT_OAUTH_GITHUB_CLIENT_SECRET:-$GITHUB_CLIENT_SECRET}' >> /entrypoint.sh && \
42+
echo 'node /app/server/index.mjs' >> /entrypoint.sh && \
43+
chmod +x /entrypoint.sh
2744

2845
USER node
29-
CMD ["node", "/app/server/index.mjs"]
46+
ENTRYPOINT [ "/entrypoint.sh" ]
3047

31-
#-----------------------------------
48+
#----------------------------------- PW layer - not used in production
3249
FROM mcr.microsoft.com/playwright:v1.49.1 AS base-playwright
3350

3451
WORKDIR /pw
@@ -44,11 +61,6 @@ COPY --chown=1000:1000 playwright.config.ts playwright.docker.config.ts tsconfig
4461

4562
RUN npm install --only=dev
4663

47-
# RUN npx playwright install --with-deps
48-
# this isn't a secret - it's only used in Playwright tests
49-
ENV NUXT_SESSION_PASSWORD=foo-foo-foo-foo-foo-foo-foo-foo-foo-foo-foo-foo
50-
# ENV CI=true
51-
5264
ENTRYPOINT [ "npx", "playwright", "test", "-c", "playwright.docker.config.ts" ]
5365

5466
#-----------------------------------

README.md

Lines changed: 60 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -89,48 +89,91 @@ The language breakdown analysis tab also displays a table showing the Accepted P
8989

9090
In the `.env` file, you can configure several environment variables that control the behavior of the application.
9191

92-
#### VUE_APP_SCOPE
92+
Public variables:
93+
- `NUXT_PUBLIC_IS_DATA_MOCKED`
94+
- `NUXT_PUBLIC_SCOPE`
95+
- `NUXT_PUBLIC_GITHUB_ENT`
96+
- `NUXT_PUBLIC_GITHUB_ORG`
97+
- `NUXT_PUBLIC_GITHUB_TEAM`
9398

94-
The `VUE_APP_SCOPE` environment variable in the `.env` file determines the scope of the API calls made by the application. It can be set to either 'enterprise' or 'organization'.
99+
can be overriden by route parameters, e.g.
100+
- `http://localhost:3000/enterprises/octo-demo-ent`
101+
- `http://localhost:3000/orgs/octo-demo-org`
102+
- `http://localhost:3000/orgs/octo-demo-org/team/the-a-team`
103+
- `http://localhost:3000/orgs/mocked-org?mock=true`
95104

96-
- If set to 'enterprise', the application will target API calls to the GitHub Enterprise account defined in the `VUE_APP_GITHUB_ENT` variable.
97-
- If set to 'organization', the application will target API calls to the GitHub Organization account defined in the `VUE_APP_GITHUB_ORG` variable.
105+
#### NUXT_PUBLIC_SCOPE
98106

99-
For example, if you want to target the API calls to an organization, you would set `VUE_APP_SCOPE=organization` in the `.env` file.
107+
The `NUXT_PUBLIC_SCOPE` environment variable in the `.env` file determines the default scope of the API calls made by the application. It can be set to 'enterprise', 'organization' or 'team'.
108+
109+
- If set to 'enterprise', the application will target API calls to the GitHub Enterprise account defined in the `NUXT_PUBLIC_GITHUB_ENT` variable.
110+
- If set to 'organization', the application will target API calls to the GitHub Organization account defined in the `NUXT_PUBLIC_GITHUB_ORG` variable.
111+
- If set to 'team', the application will target API calls to GitHub Team defined in the `NUXT_PUBLIC_GITHUB_TEAM` variable under `NUXT_PUBLIC_GITHUB_ORG` GitHub Organization.
112+
113+
For example, if you want to target the API calls to an organization, you would set `NUXT_PUBLIC_SCOPE=organization` in the `.env` file.
114+
115+
>[!INFO]
116+
> Environment variables with `NUXT_PUBLIC` scope are available in the browser (are public).
117+
> See [Nuxt Runtime Config](https://nuxt.com/docs/guide/going-further/runtime-config) for details.
100118
101119
````
102-
VUE_APP_SCOPE=organization
120+
NUXT_PUBLIC_SCOPE=organization
103121
104-
VUE_APP_GITHUB_ORG=<YOUR-ORGANIZATION>
122+
NUXT_PUBLIC_GITHUB_ORG=<YOUR-ORGANIZATION>
105123
106-
VUE_APP_GITHUB_ENT=
124+
NUXT_PUBLIC_GITHUB_ENT=
107125
````
108126

109-
#### VUE_APP_GITHUB_TEAM
127+
#### NUXT_PUBLIC_GITHUB_TEAM
110128

111-
The `VUE_APP_GITHUB_TEAM` environment variable filters metrics for a specific GitHub team within an Enterprise or Organization account.
129+
The `NUXT_PUBLIC_GITHUB_TEAM` environment variable filters metrics for a specific GitHub team within an Enterprise or Organization account.
112130
‼️ Important ‼️ When this variable is set, all displayed metrics will pertain exclusively to the specified team. To view metrics for the entire Organization or Enterprise, remove this environment variable.
113131

132+
>[!WARNING]
133+
> GitHub provides Team metrics [for a given day if the team had five or more members with active Copilot licenses, as evaluated at the end of that day.](https://docs.github.com/en/rest/copilot/copilot-usage?apiVersion=2022-11-28#get-a-summary-of-copilot-usage-for-a-team).
134+
114135
````
115-
VUE_APP_GITHUB_TEAM=
136+
NUXT_PUBLIC_GITHUB_TEAM=
116137
````
117138

118-
#### VUE_APP_MOCKED_DATA
139+
#### NUXT_PUBLIC_IS_DATA_MOCKED
119140

120-
To access Copilot metrics from the last 28 days via the API and display actual data, set the following boolean environment variable to `false`:
141+
Variable is false by default. To view mocked data switch it to true or use query parameter `?mock=true`.
121142

122143
````
123-
VUE_APP_MOCKED_DATA=false
144+
NUXT_PUBLIC_IS_DATA_MOCKED=false
124145
````
125146

126-
#### VUE_APP_GITHUB_TOKEN
147+
#### NUXT_GITHUB_TOKEN
127148

128149
Specifies the GitHub Personal Access Token utilized for API requests. Generate this token with the following scopes: _copilot_, _manage_billing:copilot_, _manage_billing:enterprise_, _read:enterprise_, _read:org_.
129150

151+
Token is not used in the frontend.
152+
130153
````
131-
VUE_APP_GITHUB_TOKEN=
154+
NUXT_GITHUB_TOKEN=
132155
````
133156

157+
#### NUXT_SESSION_PASSWORD (Required!)
158+
159+
This variable is required to encrypt user sessions, it needs to be at least 32 characters long.
160+
For more information see [Nuxt Sessions and Authentication](https://nuxt.com/docs/guide/recipes/sessions-and-authentication#cookie-encryption-key).
161+
162+
>[!WARNING]
163+
> This variable is required starting from version 2.0.0.
164+
165+
#### NUXT_PUBLIC_USING_GITHUB_AUTH
166+
167+
Default is `false`. When set to `true`, GitHub OAuth App Authentication will be performed to verify users' access to the dashboard.
168+
169+
Variables required for GitHub Auth are:
170+
1. `NUXT_OAUTH_GITHUB_CLIENT_ID` - client ID of the GitHub App registered and installed in the enterprise/org with permissions listed in [NUXT_GITHUB_TOKEN](#NUXT_GITHUB_TOKEN).
171+
2. `NUXT_OAUTH_GITHUB_CLIENT_SECRET` - client secret of the GitHub App.
172+
3. [Optional] `NUXT_OAUTH_GITHUB_CLIENT_SCOPE` for scope requests when using OAuth App instead of GitHub App. See [Github docs](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/differences-between-github-apps-and-oauth-apps) for details.
173+
174+
>[!WARNING]
175+
> Only users with permissions (scopes listed in [NUXT_GITHUB_TOKEN](#NUXT_GITHUB_TOKEN)) can view copilot metrics, GitHub uses the authenticated users permissions to make API calls for data.
176+
134177
## Install Dependencies
135178

136179
```bash
@@ -140,7 +183,7 @@ npm install
140183
### Compiles and Runs the Application
141184

142185
```bash
143-
npm run serve
186+
npm run dev
144187
```
145188

146189
### Docker Build
@@ -157,69 +200,6 @@ docker run -p 8080:80 --env-file ./.env copilot-metrics-viewer
157200

158201
The application will be accessible at http://localhost:8080
159202

160-
## Running with API Proxy
161-
162-
The project can run with an API proxy which hides GitHub tokens and is secure enough to be deployed.
163-
The API Proxy project is in the `\api` directory. The Vue app makes the calls to `/api/github` which are then proxied to `https://api.github.com` with the appropriate bearer token.
164-
165-
The proxy can authenticate the user using a GitHub App. In order to do that, the following environment variables are required:
166-
167-
* `GITHUB_CLIENT_ID` - client ID of the GitHub App registered and installed in the enterprise/org with permissions listed above.
168-
* `GITHUB_CLIENT_SECRET` - client secret of the GitHub App.
169-
* `SESSION_SECRET` - random string for securing session state.
170-
171-
If you want to use a custom path for your `.env` file, you can set the environment variable `DOTENV_CONFIG_PATH`.
172-
173-
It's also possible to run with a **PAT Token**, see examples below for required variables.
174-
175-
For local development, register `http://localhost:3000/callback` as the GitHub App callback URI.
176-
For the deployed version, use the URI of your app.
177-
178-
To build and run the app with the API proxy:
179-
180-
```bash
181-
docker build -t copilot-metrics-viewer-with-proxy -f api.Dockerfile .
182-
```
183-
184-
To run:
185-
186-
```bash
187-
docker run -it --rm -p 8080:3000 --env-file ./.env copilot-metrics-viewer-with-proxy
188-
```
189-
190-
Or with a custom path for your `.env` file:
191-
192-
```bash
193-
docker run -it --rm -p 8080:3000 \
194-
-e DOTENV_CONFIG_PATH=/custom/.env \
195-
-v /path/to/your/.env:/custom/.env \
196-
copilot-metrics-viewer-with-proxy
197-
```
198-
199-
The proxy can also run with the token hardcoded on the backend (which hides it from frontend calls), here's a sample:
200-
201-
```bash
202-
docker run -it --rm -p 3000:3000 \
203-
-e VUE_APP_SCOPE=enterprise \
204-
-e VUE_APP_GITHUB_API=/api/github \
205-
-e VUE_APP_GITHUB_ENT=<enterprise name> \
206-
-e VUE_APP_GITHUB_TOKEN=<github PAT> \
207-
-e SESSION_SECRET=<random string> \
208-
copilot-metrics-viewer-with-proxy
209-
```
210-
211-
or
212-
213-
```bash
214-
docker run -it --rm -p 3000:3000 \
215-
-e VUE_APP_SCOPE=organization \
216-
-e VUE_APP_GITHUB_API=/api/github \
217-
-e VUE_APP_GITHUB_ORG=<org name> \
218-
-e VUE_APP_GITHUB_TOKEN=<github PAT> \
219-
-e SESSION_SECRET=<random string> \
220-
copilot-metrics-viewer-with-proxy
221-
```
222-
223203
## License
224204

225205
This project is licensed under the terms of the MIT open source license. Please refer to [MIT](./LICENSE.txt) for the full terms.

azure-deploy/with-app-registration/azuredeploy.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"metrics-viewer-docker-image": {
4343
"type": "string",
44-
"defaultValue": "ghcr.io/github-copilot-resources/copilot-metrics-viewer-with-proxy:latest",
44+
"defaultValue": "ghcr.io/github-copilot-resources/copilot-metrics-viewer:latest",
4545
"metadata": {
4646
"description": "Docker image for metrics viewer - use default or replace with your own"
4747
}
@@ -96,31 +96,27 @@
9696
},
9797
"env": [
9898
{
99-
"name": "VUE_APP_SCOPE",
99+
"name": "NUXT_PUBLIC_SCOPE",
100100
"value": "[variables('app-scope')]"
101101
},
102102
{
103-
"name": "VUE_APP_GITHUB_API",
104-
"value": "/api/github"
105-
},
106-
{
107-
"name": "VUE_APP_GITHUB_ORG",
103+
"name": "NUXT_PUBLIC_GITHUB_ORG",
108104
"value": "[parameters('github-organization')]"
109105
},
110106
{
111-
"name": "VUE_APP_GITHUB_ENT",
107+
"name": "NUXT_PUBLIC_GITHUB_ENT",
112108
"value": "[parameters('github-enterprise')]"
113109
},
114110
{
115-
"name": "GITHUB_CLIENT_ID",
111+
"name": "NUXT_OAUTH_GITHUB_CLIENT_ID",
116112
"value": "[parameters('github-client-id')]"
117113
},
118114
{
119-
"name": "GITHUB_CLIENT_SECRET",
115+
"name": "NUXT_OAUTH_GITHUB_CLIENT_SECRET",
120116
"value": "[parameters('github-client-secret')]"
121117
},
122118
{
123-
"name": "SESSION_SECRET",
119+
"name": "NUXT_SESSION_PASSWORD",
124120
"value": "[uniqueString(resourceGroup().id)]"
125121
}
126122
]

azure-deploy/with-app-registration/portal.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
"type": "Microsoft.Common.TextBox",
182182
"label": "Metrics-viewer-docker-image",
183183
"subLabel": "",
184-
"defaultValue": "ghcr.io/github-copilot-resources/copilot-metrics-viewer-with-proxy:latest",
184+
"defaultValue": "ghcr.io/github-copilot-resources/copilot-metrics-viewer:latest",
185185
"toolTip": "Docker image for metrics viewer - use default or replace with your own",
186186
"constraints": {
187187
"required": false,

0 commit comments

Comments
 (0)