|
| 1 | +# Topcoder X overview |
| 2 | + |
| 3 | +Topcoder-X is a set of applications and services that allow a copilot or Topcoder customer to manage work directly through Gitlab or Github. When an issue is created in a Gitlab or Github project set up in Topcoder-X, Topcoder-X will create a Topcoder challenge to mirror the Gitlab or Github issue, and it will ensure that the challenge has the correct prize, copilot, assignee, description, and title. As the Gitlab or Github issue is updated, Topcoder-X will ensure that the Topcoder challenge associated with the issue is updated appropriately. When the Gitlab or Github issue is closed, Topcoder-X will activate and close the Topcoder challenge, ensuring that the members get paid as expected. |
| 4 | + |
| 5 | +At each step of the process, Topcoder-X will add comments to the Gitlab or Github project, ensuring that the members know where the Topcoder challenge is and what the status of the challenge is. |
| 6 | + |
| 7 | +The information is updated in real time based on webhook integrations with Gitlab and Github. Each Gitlab or Github project will have a webhook registered that sends information about issues created, updated, assigned, and deleted back to Topcoder-X for processing. |
| 8 | + |
| 9 | +# Deployment of the TopcoderX stack |
| 10 | + |
| 11 | +## Dependencies |
| 12 | +* NodeJS 8+ |
| 13 | +* MongoDB 3.2 |
| 14 | +* Kafka |
| 15 | +* nodemon (for local development) |
| 16 | + |
| 17 | +## Topcoder-X pieces |
| 18 | + |
| 19 | +Topcoder-X comprises 3 pieces: |
| 20 | + |
| 21 | +* Topcoder-X Receiver which is called from Github and Gitlab via webhooks. Github and Gitlab projects are set up with a webhook integration that calls from Github or Gitlab to the Topcoder-X receiver when events are raised. The receiver reformats the messages into standard formats and puts them into a Kafka queue for later processing |
| 22 | +* Topcoder-X Processor that handles the messages created by the receiver. The processor handles the interactions with the Topcoder platform, via the Topcoder challenge API, and it also handles adding comments back to Github / Gitlab when things are updated on the Topcoder challenge. |
| 23 | +* Topcoder-X UI that allows copilots and others to manage the Topcoder-X integrations with Github and Gitlab projects. The user can add new Github and Gitlab integrations, including setting up default webhooks and labels for issues, all through the UI. |
| 24 | + |
| 25 | +All 3 pieces will be configured to use the same MongoDB and Kafka installations. |
| 26 | + |
| 27 | + |
| 28 | +## MongoDB |
| 29 | + |
| 30 | +The MongoDB can be created using default options. Just make sure that it is configured properly as `MONGODB_URI` in all 3 pieces: |
| 31 | + |
| 32 | +* Topcoder-X processor |
| 33 | +* Topcoder-X receiver |
| 34 | +* Topcoder-X UI |
| 35 | + |
| 36 | +Sample from our development environment: |
| 37 | + |
| 38 | +`MONGODB_URI: mongodb://heroku_k366sw2n:<password>@ds135552.mlab.com:35552/heroku_k366sw2n` |
| 39 | + |
| 40 | +## Kafka |
| 41 | + |
| 42 | +Installing Kafka can be done either locally or using a cloud service. You'll need to note how the service is configured and will have to update the configuration appropriately for the receiver, processor, and site. |
| 43 | + |
| 44 | +#### Local installation: |
| 45 | + |
| 46 | +https://devops.profitbricks.com/tutorials/install-and-configure-apache-kafka-on-ubuntu-1604-1/ |
| 47 | + |
| 48 | +Make sure to install Kafka and also create an appropriate `topic`. I use `topcoder-x` as the topic name in our development environment. |
| 49 | + |
| 50 | +#### Local configuration |
| 51 | + |
| 52 | +This is a sample configuration from our development environment. The CERT and CERT_KEY are used for SSL connections, which likely won't apply locally - see below. The TOPIC value is the Kafka topic created during installation. |
| 53 | + |
| 54 | +``` |
| 55 | +KAFKA_CLIENT_CERT: <cert string> |
| 56 | +
|
| 57 | +KAFKA_CLIENT_CERT_KEY: <cert string> |
| 58 | +
|
| 59 | +KAFKA_HOST: silver-craft-01.srvs.cloudkafka.com:9093,silver-craft-01.srvs.cloudkafka.com:9094 |
| 60 | +
|
| 61 | +TOPIC: topcoder-x |
| 62 | +``` |
| 63 | + |
| 64 | +For local development, you don't need the CERT and CERT_KEY values. For the processor and receiver you can update the `config/default.js` file and remove the `ssl` section under `KAFKA_OPTIONS` |
| 65 | + |
| 66 | +So it would be updated from this: |
| 67 | + |
| 68 | +``` |
| 69 | + KAFKA_OPTIONS: { |
| 70 | + connectionString: process.env.KAFKA_HOST || 'localhost:9092', |
| 71 | + ssl: { |
| 72 | + cert: process.env.KAFKA_CLIENT_CERT || fs.readFileSync('./kafka_client.cer'), // eslint-disable-line no-sync |
| 73 | + key: process.env.KAFKA_CLIENT_CERT_KEY || fs.readFileSync('./kafka_client.key'), // eslint-disable-line no-sync |
| 74 | + } |
| 75 | + }, |
| 76 | +``` |
| 77 | + |
| 78 | +To this: |
| 79 | + |
| 80 | +``` |
| 81 | + KAFKA_OPTIONS: { |
| 82 | + connectionString: process.env.KAFKA_HOST || 'localhost:9092' |
| 83 | + }, |
| 84 | +``` |
| 85 | + |
| 86 | +## Local DNS setup |
| 87 | + |
| 88 | +For login to work, your local Topcoder-X-UI deployment needs to have a `*.topcoder-dev.com` DNS name. Our development environment uses `x.topcoder-dev.com` |
| 89 | + |
| 90 | +You can make this change in your local `/etc/hosts` file. |
| 91 | + |
| 92 | +``` |
| 93 | +127.0.0.1 x.topcoder-dev.com |
| 94 | +``` |
| 95 | + |
| 96 | +You can login with one of these sample accounts: |
| 97 | + |
| 98 | +* `mess` / `appirio123` |
| 99 | +* `tonyj` / `appirio123` |
| 100 | + |
| 101 | +## Local webhook setup |
| 102 | + |
| 103 | +The hardest part of the setup may be ensuring that Gitlab and Github can make callbacks to your local environment. You will have to ensure that your Topcoder-X receiver is publicly accessible on the public internet. |
| 104 | + |
| 105 | +If your ISP dynamically configures your IP address, you can use a dyndns service: |
| 106 | + |
| 107 | +* https://www.duckdns.org/ |
| 108 | +* https://www.noip.com/ |
| 109 | + |
| 110 | +Once you have your local Topcoder-X receiver publicly accessible, you can add a webhook like this. Note that you can also do this through the UI - just make sure to properly set the `HOOK_BASE_URL` config property of the Topcoder-X UI to match your publicly accessible domain name. |
| 111 | + |
| 112 | +#### Gitlab |
| 113 | + |
| 114 | +``` |
| 115 | +http://<publicly accessible domain name>:<port>/webhooks/gitlab |
| 116 | +``` |
| 117 | + |
| 118 | +#### Github |
| 119 | + |
| 120 | +``` |
| 121 | +https://<publicly accessible domain name>:<port>/webhooks/github |
| 122 | +``` |
| 123 | + |
| 124 | +## Account setup |
| 125 | + |
| 126 | +Once all 3 services are running, you should be able to login to the Topcoder-X UI. The first thing to do is set up the Gitlab and Github account mapping for your account. |
| 127 | + |
| 128 | +You can do this by clicking your logged in username in the upper right of the Topcoder-X UI and clicking `Settings`. This will allow you to register with both Github and Gitlab. Both should show a check mark indicating they have been properly set up. |
| 129 | + |
| 130 | +## Testing |
| 131 | + |
| 132 | +Once you have registered your account, go into `Project Management` and add a new project for either a Gitlab or Github project you have access to. Gitlab is likely easier for testing - you can create a free test project under your own account. |
| 133 | + |
| 134 | +Use Topcoder Direct ID `7377` since this has a valid billing account in the dev environment. |
| 135 | + |
| 136 | +Once it's been added, click `Edit` for the project in the list on `Project Management` and click `Add Webhooks`. Once the webhook has been added, you should be able to see it in the Gitlab project under `Settings` --> `Integrations` --> `Webhooks` |
| 137 | + |
| 138 | +To test the webhook, create a new issue in the project with a title like `[$1] This is a test issue` |
| 139 | + |
| 140 | +You should see the message passed successfully from the webhook to the receiver and then processed. |
| 141 | + |
| 142 | +If the flow works properly, you will see a comment like this added to the Gitlab issue: |
| 143 | + |
| 144 | +``` |
| 145 | +Contest https://www.topcoder-dev.com/challenges/30052039 has been created for this ticket. |
| 146 | +``` |
| 147 | + |
| 148 | +You can test assignment by assigning the ticket to yourself. You should then see another message after a few seconds like this: |
| 149 | + |
| 150 | +``` |
| 151 | +Contest https://www.topcoder-dev.com/challenges/30052039 has been updated - it has been assigned to tonyj. |
| 152 | +``` |
| 153 | + |
| 154 | +## Sample development configs |
| 155 | + |
| 156 | +For reference, this is what the sample configs look like in our development environment, which should closely match your local deployment environment. |
| 157 | + |
| 158 | +You can use the Gitlab and Github keys and secrets below, but you are also welcome to create your own. |
| 159 | + |
| 160 | +#### Topcoder-X processor |
| 161 | +``` |
| 162 | +Justins-Mac-Pro:~ justingasper$ heroku config --app topcoder-x-processor-dev |
| 163 | +=== topcoder-x-processor-dev Config Vars |
| 164 | +EMAIL_SENDER_ADDRESS: [email protected] |
| 165 | +ISSUE_BID_EMAIL_RECEIVER: [email protected] |
| 166 | +KAFKA_CLIENT_CERT: <cert> |
| 167 | +KAFKA_CLIENT_CERT_KEY: <key> |
| 168 | +KAFKA_HOST: silver-craft-01.srvs.cloudkafka.com:9093,silver-craft-01.srvs.cloudkafka.com:9094 |
| 169 | +LOG_LEVEL: debug |
| 170 | +MAILGUN_API_KEY: key-5ebe7a0fae37a9008721ec0bfe5bdd95 |
| 171 | +MAILGUN_DOMAIN: sandbox3fcf4920781449f2a5293f8ef18e4bb6.mailgun.org |
| 172 | +MAILGUN_PUBLIC_KEY: pubkey-cb9640c444199bcec987010b6d9ef0d2 |
| 173 | +MAILGUN_SMTP_LOGIN: [email protected] |
| 174 | +MAILGUN_SMTP_PASSWORD: c8aefb446e76febdbc31d57ef30b9c10 |
| 175 | +MAILGUN_SMTP_PORT: 587 |
| 176 | +MAILGUN_SMTP_SERVER: smtp.mailgun.org |
| 177 | +MONGODB_URI: mongodb://heroku_k366sw2n:<password>@ds135552.mlab.com:35552/heroku_k366sw2n |
| 178 | +NODE_DEBUG: app |
| 179 | +NODE_ENV: development |
| 180 | +NODE_MODULES_CACHE: false |
| 181 | +NODE_TLS_REJECT_UNAUTHORIZED: 0 |
| 182 | +TOPIC: topcoder-x |
| 183 | +``` |
| 184 | + |
| 185 | +#### Topcoder-X receiver |
| 186 | + |
| 187 | +``` |
| 188 | +Justins-Mac-Pro:~ justingasper$ heroku config --app topcoder-x-receiver-dev |
| 189 | +=== topcoder-x-receiver-dev Config Vars |
| 190 | +KAFKA_CLIENT_CERT: <cert> |
| 191 | +KAFKA_CLIENT_CERT_KEY: <key> |
| 192 | +KAFKA_HOST: silver-craft-01.srvs.cloudkafka.com:9093,silver-craft-01.srvs.cloudkafka.com:9094 |
| 193 | +LOG_LEVEL: debug |
| 194 | +MONGODB_URI: mongodb://heroku_k366sw2n:<password>@ds135552.mlab.com:35552/heroku_k366sw2n |
| 195 | +NODE_ENV: development |
| 196 | +NODE_TLS_REJECT_UNAUTHORIZED: 0 |
| 197 | +TOPIC: topcoder-x |
| 198 | +``` |
| 199 | + |
| 200 | +#### Topcoder-X UI |
| 201 | + |
| 202 | +``` |
| 203 | +Justins-Mac-Pro:~ justingasper$ heroku config --app topcoder-x-ui-dev |
| 204 | +=== topcoder-x-ui-dev Config Vars |
| 205 | +BUILD_ENV: heroku |
| 206 | +GITHUB_CLIENT_ID: 92c7cb8cfe7561dd61b8 |
| 207 | +GITHUB_CLIENT_SECRET: ee677a9d6a8f29629d0cb74886d521df69293515 |
| 208 | +GITLAB_CLIENT_ID: 6a4f73563e7a984eef7511e2a5a6cf38567d3664628360f632cfc6c8e4e5f612 |
| 209 | +GITLAB_CLIENT_SECRET: 70367d8255e160828ae47f35ff71723202afc7be1f29a4c7319bc82c4dd47c6b |
| 210 | +HOOK_BASE_URL: https://topcoder-x-receiver-dev.herokuapp.com |
| 211 | +KAFKA_CLIENT_CERT: <cert> |
| 212 | +KAFKA_CLIENT_CERT_KEY: <key> |
| 213 | +KAFKA_HOST: silver-craft-01.srvs.cloudkafka.com:9093,silver-craft-01.srvs.cloudkafka.com:9094 |
| 214 | +MONGODB_URI: mongodb://heroku_k366sw2n:<password>@ds135552.mlab.com:35552/heroku_k366sw2n |
| 215 | +NPM_CONFIG_PRODUCTION: false |
| 216 | +SESSION_SECRET: kjsdfkj34857 |
| 217 | +TC_LOGIN_URL: https://accounts.topcoder-dev.com/member |
| 218 | +TC_USER_PROFILE_URL: http://api.topcoder-dev.com/v2/user/profile |
| 219 | +TOPIC: topcoder-x |
| 220 | +WEBSITE: https://x.topcoder-dev.com |
| 221 | +``` |
0 commit comments