Skip to content

Commit 5f8dca9

Browse files
authored
ARC 2043 - [Nice to Have] Uninstall/Install connect app automatically on startup (#32)
1 parent 66e3389 commit 5f8dca9

File tree

13 files changed

+107
-30
lines changed

13 files changed

+107
-30
lines changed

.env.example

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ NGROK_AUTHTOKEN=
44
# [AUTOFILL] This URL is automatically filled
55
APP_URL=
66

7+
# These variables are needed for the auto-app installation
8+
INSTALL_ATLASSIAN_URL=
9+
INSTALL_JIRA_ADMIN_USERNAME=
10+
# Create a new API token in Jira [https://id.atlassian.com/manage-profile/security/api-tokens]
11+
INSTALL_JIRA_ADMIN_PASSWORD=
12+
713
# These variables need to be filled only for running E2E test
8-
ATLASSIAN_URL=
9-
JIRA_ADMIN_USERNAME=
10-
JIRA_ADMIN_PASSWORD=
14+
E2E_ATLASSIAN_URL=
15+
E2E_JIRA_ADMIN_USERNAME=
16+
E2E_JIRA_ADMIN_PASSWORD=

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ jobs:
5050
run: |
5151
echo "APP_URL=http://localhost" > .env
5252
echo "NGROK_AUTHTOKEN=${{ secrets.NGROK_AUTHTOKEN }}" >> .env
53-
echo "ATLASSIAN_URL=${{ secrets.ATLASSIAN_URL }}" >> .env
54-
echo "JIRA_ADMIN_USERNAME=${{ secrets.JIRA_ADMIN_USERNAME }}" >> .env
55-
echo "JIRA_ADMIN_PASSWORD=${{ secrets.JIRA_ADMIN_PASSWORD }}" >> .env
53+
echo "E2E_ATLASSIAN_URL=${{ secrets.E2E_ATLASSIAN_URL }}" >> .env
54+
echo "E2E_JIRA_ADMIN_USERNAME=${{ secrets.E2E_JIRA_ADMIN_USERNAME }}" >> .env
55+
echo "E2E_JIRA_ADMIN_PASSWORD=${{ secrets.E2E_JIRA_ADMIN_PASSWORD }}" >> .env
5656
- run: docker-compose up -d
5757
- run: yarn run test:e2e

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
FROM node:lts-alpine as build
22

3+
RUN apk --no-cache add curl
4+
35
COPY . /app
46
WORKDIR /app
57

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [WIP] Atlassian Connect example app - Node edition
1+
# Atlassian Connect example app - Node edition
22

33
> **_NOTE:_** This repository is in progress and is not ready yet.
44
@@ -10,6 +10,7 @@ This app is aimed to help you to easily add your integration in Jira.
1010
- [Pre-requisites](#pre-requisites)
1111
- [Features](#features)
1212
- [Getting started](#getting-started)
13+
- [Manual Install](#manually-installing-the-app)
1314
- [Running your application](#running-your-application)
1415
- [Testing](#testing)
1516
- [Getting help](#getting-help)
@@ -25,23 +26,30 @@ This app is aimed to help you to easily add your integration in Jira.
2526

2627
## Getting started
2728
You can run this app in 3 simple steps:
28-
- **Installing dependencies** - Run `yarn install` for installing all the dependencies for this app.
29+
- **Installing dependencies**
30+
- Run `yarn install` for installing all the dependencies for this app.
2931

30-
- **Tunneling** - For this purpose, we are using [ngrok](https://ngrok.com/docs/getting-started). You need to set the ngrok authtoken in the env file, so please make sure you have a ngrok account.
31-
Simply go to [ngrok](https://dashboard.ngrok.com/get-started/your-authtoken) and copy your authtoken and paste it in the [.env](./.env) file.
32+
- **Tunneling**
33+
- For this purpose, we are using [ngrok](https://ngrok.com/docs/getting-started). You need to set the ngrok authtoken in the env file, so please make sure you have a ngrok account.
34+
- Simply go to [ngrok](https://dashboard.ngrok.com/get-started/your-authtoken) and copy your authtoken and paste it in the [.env](./.env) file.
3235

33-
- **Running docker compose** - Then simply run `docker-compose up`. Once the docker finishes running, you can view the tunneled URL in the logs.
34-
![img.png](static/images/tunnel-output.png)
36+
- **Running docker compose**
37+
- Then simply run `docker-compose up`.
38+
- Please be patient as it will take a few minutes for everything to be setup. When everything is setup, you should see the URL in the terminal as in the picture below. ![img.png](static/images/tunnel-output.png)
3539

36-
After you have the tunneled URL, check for the config in the url `/atlassian-connect.json`(`https://TUNNELED_URL/atlassian-connect.json`). This is the __app descriptor URL__ for uploading the app and installing in Jira.
40+
> **Note:** _If you are using a free version of ngrok, please open the tunneled URL first. This needs to be done to bypass the ngrok browser warning. Just visit the ngrok warning page and just click on the Visit button._
3741
38-
## Installing the App
39-
Go to your Jira instance and do the following steps:
42+
At the very end, you can see the URL the index page of your app. Just open the URL and that's it, you're ready!
43+
44+
## Manually Installing the App
45+
The above steps automatically installs the app, however you can only install one app at a time.
46+
47+
So, if you want to install the app in multiple Jira instances, please do it manually. Go to your Jira instances and do the following steps:
4048
- From the header menu, select Apps -> Manage your apps.
4149
- Verify the filter is set to User-installed, and select Settings beneath the User-installed apps table.
42-
- On the Settings pop-up, add Enable development mode and click Apply. Refresh the page.
50+
- On the Settings pop-up, add Enable development mode and click Apply. Refresh the page.
4351
- On the right side of the header, there should now appear a button Upload app. Click it and enter the tunneled URL `/atlassian-connect.json`(`https://TUNNELED_URL/atlassian-connect.json`)
44-
- Click Upload.
52+
- Click Upload.
4553
- That's it! You're done. 🎉
4654

4755
## Running your application

app-install/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM ubuntu:latest
2+
3+
COPY app-install/app-install.sh ./app-install.sh
4+
RUN chmod +x app-install.sh
5+
6+
RUN apt update
7+
RUN apt install -y curl jq
8+
9+
CMD ["bash", "app-install.sh"]

app-install/app-install.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# App key defined for this sample app
2+
APP_KEY=com.atlassian.sample-app-node
3+
# Fetching the new ngrok URL, not fetching the one from the .env because its not updated
4+
BASE_URL=$(curl --silent http://tunnel:4040/api/tunnels | jq -r '.tunnels[] | select(.proto == "https") | .public_url')
5+
6+
# Bypassing the ngrok warning page
7+
curl -H "ngrok-skip-browser-warning: 1" BASE_URL
8+
9+
# Uninstalling the app first
10+
curl -X DELETE -u $INSTALL_JIRA_ADMIN_USERNAME:$INSTALL_JIRA_ADMIN_PASSWORD \
11+
-H "Content-Type: application/vnd.atl.plugins.install.uri+json" "${INSTALL_ATLASSIAN_URL}/rest/plugins/1.0/${APP_KEY}-key"
12+
echo "Uninstalling old version of the app \n\n"
13+
14+
# Getting the UPM token first, which will be used for app installation
15+
UPM_TOKEN=$(curl -u $INSTALL_JIRA_ADMIN_USERNAME:$INSTALL_JIRA_ADMIN_PASSWORD --head ${INSTALL_ATLASSIAN_URL}/rest/plugins/1.0/| fgrep upm-token | cut -c 12- | tr -d '\r\n')
16+
17+
# Installing the app
18+
curl -u $INSTALL_JIRA_ADMIN_USERNAME:$INSTALL_JIRA_ADMIN_PASSWORD -H "Content-Type: application/vnd.atl.plugins.install.uri+json" \
19+
-X POST ${INSTALL_ATLASSIAN_URL}/rest/plugins/1.0/?token=${UPM_TOKEN} \
20+
-d "{\"pluginUri\":\"${BASE_URL}/atlassian-connect.json\", \"pluginName\": \"Sample Connect Node App\"}"
21+
22+
echo "The app has been successfully installed \n\n"
23+
echo "
24+
*********************************************************************************************************************
25+
IF YOU ARE USING A FREE NGROK ACCOUNT, PLEASE DO THIS STEP FIRST!!!
26+
Before going to your app, please open this URL first: ${BASE_URL}.
27+
This will open up the ngrok page, don't worry just click on the Visit button.
28+
That's it, you're all ready!
29+
*********************************************************************************************************************
30+
*********************************************************************************************************************
31+
Now open your app in this URL: ${INSTALL_ATLASSIAN_URL}/plugins/servlet/ac/${APP_KEY}/acn-introduction
32+
*********************************************************************************************************************
33+
"

docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,18 @@ services:
1717
ports:
1818
- "3000:3000" # server port
1919
- "9229:9229" # debug port
20+
healthcheck:
21+
test: ["CMD", "curl", "-f", "http://localhost:3000/healthcheck"]
22+
interval: 10s
23+
retries: 5
24+
25+
installation:
26+
container_name: install-in-jira
27+
depends_on:
28+
app:
29+
condition: service_healthy
30+
build:
31+
context: .
32+
dockerfile: app-install/Dockerfile
33+
env_file:
34+
- .env

src/env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ export type EnvVars = {
44
APP_URL: string;
55
APP_KEY: string;
66
NGROK_AUTHTOKEN: string;
7+
INSTALL_ATLASSIAN_URL: string;
8+
INSTALL_JIRA_ADMIN_USERNAME: string;
9+
INSTALL_JIRA_ADMIN_PASSWORD: string;
710
};
811

912
const variables = config().parsed as Partial<EnvVars>;

src/routes/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const RootRouter = Router();
1111

1212
/************************************************************************************************************************
1313
* Healthcheck
14-
************************************************************************************************************************/
14+
************************************************************************************************************************/
1515
RootRouter.get("/healthcheck", (_req, res) => res.status(200).send("Healthy!"));
1616

1717
/************************************************************************************************************************

src/server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ app.use(json());
2323
app.use(RootRouter);
2424

2525
const port = 3000;
26-
app.listen(port, () => {
27-
console.log(`Example app listening on port ${port}`);
26+
app.listen(port, async () => {
27+
// App is now running
28+
console.log(`Sample app listening on port ${port}`);
2829
});

0 commit comments

Comments
 (0)