|
| 1 | +# quay/imagestream-sync |
| 2 | + |
| 3 | +This implementation is used to synchronize images that are stored in [Quay](https://coreos.com/quay-enterprise/) and are referenced as ImageStreams within the OpenShift Container Platform from [Quay notifications](https://docs.quay.io/guides/notifications.html). |
| 4 | + |
| 5 | + |
| 6 | +## Requirements |
| 7 | + |
| 8 | +Although this can be run as a regular/standalone `node.js` app, it is recommended that this gets deployed on an OpenShift Container Platform for ease of maintenance. A minimum of NodeJS version 8 is required. |
| 9 | + |
| 10 | +## Configuration Options |
| 11 | + |
| 12 | +The following configuration items tune and control the behavior of the application. |
| 13 | + |
| 14 | +| Variable | Description | Defaults | |
| 15 | +|:---------|:------------|:---------| |
| 16 | +| HTTP_PORT | The http port for the application to listen on | 8080 | |
| 17 | +| HTTPS_PORT | The httpd (SSL) port for the application listen on (choose this or HTTP_PORT above) | 8443 | |
| 18 | +| HTTPS_SSL_CERTIFICATE | When HTTPS_PORT above is used, specify the certificate here | | |
| 19 | +| HTTPS_SSL_KEY | When the HTTPS_PORT above is used, specify the certificate key here | | |
| 20 | +| TOKEN_FILE | Location of a file containing the contents of an OAuth token to authenticate to the OpenShift API | `/var/run/secrets/kubernetes.io/serviceaccount/token` | |
| 21 | +| CA_FILE | Location of the certificate to communicate securely with the OpenShift API | `/var/run/secrets/kubernetes.io/serviceaccount/ca.crt` | |
| 22 | +| AUTH_TOKEN | Value of the token used to communicate with the OpenShift API | | |
| 23 | +| MASTER_URL | Address of the OpenShift Master | `https://kubernetes.default.svc:443` | |
| 24 | +| TLS_INSECURE | Allow insecure communication to the OpenShift API | `false` | |
| 25 | +| NAMESPACE | Single namespace to allow image synchronization (defaults to entire cluster) | | |
| 26 | + |
| 27 | +## Running in OpenShift |
| 28 | + |
| 29 | +### Prerequisites |
| 30 | + |
| 31 | +This application makes queries to the OpenShift API. The service account associated with the application must have sufficient rights to query for ImageStreams either at a cluster scope or namespace scope. |
| 32 | + |
| 33 | +The following command can be added to grant access to a service account at a cluster level using the included `registry-editor` ClusterRole. |
| 34 | + |
| 35 | +``` |
| 36 | +$ oc adm policy add-cluster-role-to-user registry-editor -z <service-account> |
| 37 | +``` |
| 38 | + |
| 39 | +To limit to a single namespace, the following command can be used: |
| 40 | + |
| 41 | +``` |
| 42 | +$ oc project <namespace> |
| 43 | +$ oc policy add-role-to-user registry-editor -z <service-account> |
| 44 | +``` |
| 45 | + |
| 46 | +### Application Deployment |
| 47 | + |
| 48 | +The `oc new-app` command in combination with `oc expose` command can be used to deploy the application: |
| 49 | + |
| 50 | +``` |
| 51 | +$ oc new-app --name=quay-imagestream-sync openshift/nodejs:8~https://github.com/redhat-cop/tool-integrations.git --context-dir=quay/imagestream-sync |
| 52 | +$ oc expose service quay-imagestream-sync |
| 53 | +``` |
| 54 | + |
| 55 | +Then add the environment variables below, and add a github webhook (with the `route` url) to test it out. |
| 56 | + |
| 57 | +## Quay Configuration |
| 58 | + |
| 59 | +The final step is to configure Quay to send webhook notifications to the application deployed in OpenShift. |
| 60 | + |
| 61 | +First, obtain the url of the application previously deployed. |
| 62 | + |
| 63 | +``` |
| 64 | +$ oc get routes quay-imagestream-sync --template='{{ .spec.host }}' |
| 65 | +``` |
| 66 | + |
| 67 | +Login to quay and locate the repository associated with the image that has been previously configured in OpenShift. |
| 68 | + |
| 69 | +Click on **Settings** and then **Create Notification** |
| 70 | + |
| 71 | +Under _When this event occurs_ dropdown, select **Push to Repository**. |
| 72 | + |
| 73 | +Under _Then issue a Notification_ dropdown, select **Webhook POST** |
| 74 | + |
| 75 | +Enter the URL of the webhook based on the result from the route found previously (such as `http://quay-imagestream-sync.myproject.apps.ocp.example.com`) |
| 76 | + |
| 77 | +Optionally, provide a _Notification title_ to easily identify the webhook. |
| 78 | + |
| 79 | +Select **Create Notification** |
| 80 | + |
| 81 | + |
| 82 | +License |
| 83 | +------- |
| 84 | + |
| 85 | +Apache License 2.0 |
| 86 | + |
| 87 | + |
| 88 | +Author Information |
| 89 | +------------------ |
| 90 | + |
| 91 | +Red Hat Community of Practice |
0 commit comments