|
| 1 | + |
| 2 | +Inventory |
| 3 | +========= |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +This application generates a machine-readable software inventory compliant |
| 8 | +with [Code.gov Metadata Schema version 2.0.0][1]. To accomplish this goal, |
| 9 | +the application connects to a series of Git hosting API "endpoints", |
| 10 | +inspects the configured projects, and generates an inventory. This application has been enhanced to automate the generation of the [Agency's code.json file](https://code-json-cg.app.cloud.gov/code.json) through GitHub Actions. |
| 11 | + |
| 12 | +The application configuration supports internal/external hosting platforms |
| 13 | +with or without authentication (for private repositories). It currently works |
| 14 | +with GitHub and GitLab REST APIs but could easily be extended for other hosting |
| 15 | +platform APIs as well. |
| 16 | + |
| 17 | +For each project, the application will attempt to use a developer-provided |
| 18 | +"code.json" snippet which is a JSON file containing the "releases" array |
| 19 | +for the project as defined by the [Code.gov Metadata Schema version 2.0.0][1]. |
| 20 | + |
| 21 | +If a "code.json" snippet file is not provided by the project maintainer, the |
| 22 | +application will attempt to infer sufficient/required properties from the |
| 23 | +target project and generate the best possible metadata for inclusion in the |
| 24 | +agency inventory. |
| 25 | + |
| 26 | +Generating the code.json file |
| 27 | +--------------- |
| 28 | +The code.json file can be generated by any of the GitHub Actions: |
| 29 | + |
| 30 | +1. The [daily.yml](https://github.com/USEPA/code-json-generator/actions/workflows/daily.yml) generates the code.json file to this repository's [output branch](https://github.com/USEPA/code-json-generator/tree/output). |
| 31 | + |
| 32 | +2. The [daily-deploy.yml](https://github.com/USEPA/code-json-generator/actions/workflows/daily-deploy.yml) generates the code.json file to this repository's [master branch](https://github.com/USEPA/code-json-generator/tree/master). Currently, this workflow is not active. |
| 33 | + |
| 34 | +3. The [go-push (replacing Build and Deploy)](https://github.com/USEPA/code-json-generator/actions/workflows/go-push.yml) generates the code.json file to this repository's [master branch](https://github.com/USEPA/code-json-generator/tree/master) on the git push command. Currently, this workflow is not active. |
| 35 | + |
| 36 | +Branch Directory |
| 37 | +--------------- |
| 38 | +1. output - includes the code.json file generated by the [daily.yml](https://github.com/USEPA/code-json-generator/actions/workflows/daily.yml). |
| 39 | +2. cloudgov-deployment - provides intial code-json-generator GitHub Action workflow and removes 4000+ commit history generating the code.json file and deploying to cloud.gov. |
| 40 | +3. including-history and history-cloud.gov-deployment - provides intial code-json-generator GitHub Action workflow and includes 4000+ commit history generating the code.json file and deploying to cloud.gov. |
| 41 | + |
| 42 | + |
| 43 | +Getting Started - deploying to cloud.gov |
| 44 | +--------------- |
| 45 | + |
| 46 | +This section describes the process to acquire and run the code-json-generator |
| 47 | +application in cloud.gov with the daily-deploy.yml workflow. |
| 48 | + |
| 49 | +### Prerequisites |
| 50 | + |
| 51 | +This application is a command line Node application. Node must be installed |
| 52 | +on the system prior to running this application. |
| 53 | + |
| 54 | +[https://nodejs.org/][2] |
| 55 | + |
| 56 | +### Install the application |
| 57 | + |
| 58 | +On the command line: |
| 59 | +``` |
| 60 | +$ npm install -g code-json-generator |
| 61 | +``` |
| 62 | + |
| 63 | +### Configure the application runtime |
| 64 | + |
| 65 | +The application requires a configuration file to dictate which repositories |
| 66 | +to include in the generated inventory. An [example configuration file][3] |
| 67 | +is provided to help get started. |
| 68 | + |
| 69 | +1. Update the configuration file with your Agency's respective endpoints. |
| 70 | +2. Delete the existing create-agency-inventory-config.js file in the bin folder. |
| 71 | +3. Move the new configuration file from the etc folder into the bin folder. |
| 72 | +4. Rename the configuration file to create-agency-inventory-config.js. |
| 73 | + |
| 74 | +Running locally or on cloud.gov |
| 75 | +------------------------------- |
| 76 | +You can run the code.json generator locally or deploy it to cloud.gov. |
| 77 | + |
| 78 | +### Run the application locally |
| 79 | + |
| 80 | +Running the application locally will help identify the specific repositories with missing or invalid code.json files. After all repositories have a valid code.json file, running the application will generate the Agency code.json locally. |
| 81 | + |
| 82 | +The application provides command-line usage syntax help via the `--help` switch. |
| 83 | +``` |
| 84 | +$ create-inventory.js --help |
| 85 | +
|
| 86 | + Usage: create-inventory [options] |
| 87 | +
|
| 88 | + Options: |
| 89 | +
|
| 90 | + -V, --version output the version number |
| 91 | + -c, --configFile <file> Configuration file |
| 92 | + -h, --help output usage information |
| 93 | +``` |
| 94 | +To run the application locally, you need to: |
| 95 | + |
| 96 | +1. Change the working directory to the bin folder. |
| 97 | + |
| 98 | +2. To generate an inventory, run the application and provide a configuration file |
| 99 | +using the `--configFile <file>` switch. The generated inventory will, by |
| 100 | +default, be printed to STDOUT. This output can be redirected to a file |
| 101 | +for persistence. |
| 102 | + |
| 103 | +``` |
| 104 | +$ create-inventory.js --configFile ./create-agency-inventory.config.json > code.json |
| 105 | +``` |
| 106 | +> Note: This example assumes a file containing proper configuration is located |
| 107 | +> in the current working directory and is called `create-agency-inventory.config.json`. |
| 108 | +> Adjust this usage to suit actual work environment. |
| 109 | +
|
| 110 | +Deployment to Cloud.gov with GitHub Actions |
| 111 | +------------------------------------------- |
| 112 | +You can deploy the app to Cloud.gov with GitHub Actions. |
| 113 | + |
| 114 | +### Prerequisites |
| 115 | +To do this you will need a Cloud.gov account and the [Cloud Foundry Command Line Tools](https://github.com/cloudfoundry/cli#installers-and-compressed-binaries) installed on your machine. |
| 116 | + |
| 117 | +1. Login to cloud.gov |
| 118 | +2. Navigate to your organization's space which the app will be deployed to. |
| 119 | +3. Follow the documentation to create a cloud.gov service account plan: [space deployer](https://cloud.gov/docs/services/cloud-gov-service-account/) for continuous deployment to Cloud.gov. |
| 120 | +4. Add the service key username as the CG_USERNAME secret in the GitHub Repository's Secrets. |
| 121 | +5. Add the service key username as the CG_USERNAME secret in the GitHub Repository's Secrets. |
| 122 | + |
| 123 | +### Deploying to cloud.gov |
| 124 | + |
| 125 | +You need to establish the name of your application before deploying it to cloud.gov. |
| 126 | + |
| 127 | +1. Change the working directory to the etc/manifests folder. |
| 128 | + |
| 129 | +2. Open the frontend.yml file. |
| 130 | + |
| 131 | +3. Update the applications "name:" to whatever subdomain you wish to use (e.g., your-app-name). |
| 132 | + |
| 133 | +4. Save, commit and push your changes. |
| 134 | + |
| 135 | +5. You will see the code.json file located at: your-app-name.app.cloud.gov/code.json |
| 136 | + |
| 137 | +### Update frequency of the Agency's code.json file |
| 138 | + |
| 139 | +You can modify how frequently the Agency's code.json file is generated and published to cloud.gov. |
| 140 | + |
| 141 | +1. Change the working directory to the .github/workflows folder. |
| 142 | + |
| 143 | +2. Open the daily-deploy.yml file. |
| 144 | + |
| 145 | +3. Update the `schedule` event per the desired frequency. |
| 146 | + |
| 147 | +4. Save, commit and push your changes. |
| 148 | + |
| 149 | +Agency code.json Daily update through GitHub Actions |
| 150 | +------------------------------------------- |
| 151 | + |
| 152 | +GitHub Actions is being used to run a scheduled event to create the Agency's code.json file daily. |
| 153 | + |
| 154 | +As mentioned earlier, if a "code.json" snippet file is not provided by the project maintainer, the |
| 155 | +application will attempt to infer sufficient/required properties from the |
| 156 | +target project and generate the best possible metadata for inclusion in the |
| 157 | +agency inventory. |
| 158 | + |
| 159 | +The example EPA Agency code.json for the github.com/USEPA organization can be [found here](https://code-json-cg.app.cloud.gov/code.json). |
| 160 | + |
| 161 | +Development |
| 162 | +----------- |
| 163 | + |
| 164 | +To develop and possibly contribute to this project please review the |
| 165 | +[code of conduct][4] and [contributing guidelines][5]. |
| 166 | + |
| 167 | +### Obtain the source code |
| 168 | + |
| 169 | +Potentially fork this repository and then clone the fork to obtain the source |
| 170 | +code. |
| 171 | + |
| 172 | +``` |
| 173 | +$ git clone <fork_urn>/code-json-generator.git |
| 174 | +$ cd code-json-generator |
| 175 | +``` |
| 176 | + |
| 177 | +### Develop in a feature branch |
| 178 | + |
| 179 | +Updates should be developed in a feature branch on the local clone of a fork. |
| 180 | +``` |
| 181 | +$ git checkout -b feature-X |
| 182 | +``` |
| 183 | + |
| 184 | +### Submit pull requests for review and integration |
| 185 | + |
| 186 | +Commit changes to feature branches and push feature branches to the forked |
| 187 | +remote. Submit a pull request back to this upstream repository for review |
| 188 | +and integration. If the pull request fixes an open issue on this repository, |
| 189 | +include the text `fixes #N` (where `N` is the issue number fixed) in the |
| 190 | +pull request title or description. |
| 191 | +``` |
| 192 | +$ git commit -am 'Implemented feature' |
| 193 | +$ git push origin feature-X |
| 194 | +``` |
| 195 | + |
| 196 | + |
| 197 | +[1]: https://code.gov/#/policy-guide/docs/compliance/inventory-code |
| 198 | +[2]: https://nodejs.org/ |
| 199 | +[3]: ./etc/config-example.json |
| 200 | +[4]: ./CODE_OF_CONDUCT.md |
| 201 | +[5]: ./CONTRIBUTING.md |
| 202 | + |
| 203 | +### Credits |
| 204 | + |
| 205 | +This repository reused material from the [USGS code-json-generator repository](https://github.com/usgs/code-json-generator/). |
| 206 | + |
| 207 | +### Disclaimer |
| 208 | + |
| 209 | +The United States Environmental Protection Agency (EPA) GitHub project code is provided on an "as is" basis and the user assumes responsibility for its use. EPA has relinquished control of the information and no longer has responsibility to protect the integrity , confidentiality, or availability of the information. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or favoring by EPA. The EPA seal and logo shall not be used in any manner to imply endorsement of any commercial product or activity by EPA or the United States Government. |
0 commit comments