Content Sources is an application for storing information about external content (currently YUM repositories) in a central location as well as creating snapshots of those repositories, backed by a Pulp server.
To read more about Content Sources use cases see:
- podman & podman-compose Do not use v1.3.0, or docker & docker-compose, installed and running (and Orbstack for Mac))
- This is used to start a set of containers that are dependencies for content-sources-backend
- yaml2json tool installed (
pip install json2yaml).
Create a config file from the example:
cp ./configs/config.yaml.example ./configs/config.yamlsudo echo "<your-host-ip> pulp.content" | sudo tee -a /etc/hostsYou can find your host IP by running ifconfig or ip addr list.
If you have a virtual bridge interface (virbr0, started up by running virt-manager), then you can use that IP.
make compose-upIf you want to start containers without initializing any data:
make compose-runmake repos-import-rhel9or import them all
make repos-importmake process-reposIf you want less Red Hat repos:
OPTIONS_REPOSITORY_IMPORT_FILTER=small make repos-importThis will import and snapshot repos needed for the minimal viable environment. Useful for running Playwright tests.
make repos-minimalmake runHit the API:
curl -H "$( ./scripts/header.sh 9999 1111 )" http://localhost:8000/api/content-sources/v1.0/repositories/When its time to shut down the running containers:
make compose-downClean the volume that it uses (this stops the container before doing it if it were running):
make compose-cleanThere are other make rules that could be helpful, run
make helpto list them. Some are highlighted below
- Ensure that the backend server is running
- Ensure the correct node version, is installed and in use:
cd _playwright-testsandnvm use - Copy the env file and create a file at: _playwright-tests/.env
For local development only the BASE_URL:
http://127.0.0.1:8000is required, which is already set in the example config.
make playwrightOR
cd _playwright-tests \
&& yarn install \
&& yarn playwright install \
&& yarn playwright testYou can add new migration files, with the prefixed date attached to the file name, by running the following:
go run cmd/dbmigrate/main.go new <name of migration>
Migrate the Database
make db-migrate-upGet an interactive shell:
make db-shellOr open directly a postgres client by running:
make db-cli-connectYou can open an interactive shell by:
make kafka-shellYou can run kafka-console-consumer.sh using KAFKA_TOPIC by:
make kafka-topic-consume KAFKA_TOPIC=my-kafka-topic
make kafka-topic-consume # Use the first topic at KAFKA_TOPICS listThere are other make rules that could be helpful, run
make helpto list them.
Create the configuration for prometheus, getting started with the example one.
Update the configs/prometheus.yaml file to set your hostname instead of localhost at scrape_configs.job_name.targets:
# Note that the targets object cannot reference localhost, it needs the name of your host where
# the prometheus container is executed.
cat ./configs/prometheus.example.yaml | sed "s/localhost/$(hostname)/g" > ./configs/prometheus.yamlTo start prometheus run:
make prometheus-upTo stop prometheus container run:
make prometheus-downTo open the prometheus web UI, once the container is up, run the below:
make prometheus-uiConfiguration requirements
-
To use this you need to enable RBAC into
config/configs.yamlfile:clients: rbac_enabled: True rbac_base_url: http://localhost:8800/api/rbac/v1 rbac_timeout: 30 mocks: rbac: user_read_write: ["[email protected]", "jdoe"] user_read: ["[email protected]", "tdoe"] kessel: user_read_write: ["write-user"] user_read: ["read-user"] user_no_permissions: ["no-perms-user"]
Running it
- Run the application by:
make runor./release/content-sources api consumer instrumentation mock_rbac. - Make some request using:
./scripts/header.sh 12345 [email protected]for admin or./scripts/header.sh 12345 [email protected]for viewer.
RBAC mock service is started for
make runTo use it running directly the service:./release/content-sources api consumer instrumentation mock_rbacAdd the optionmock_rbac
Kessel
- The kessel permissions will be used if the kessel feature is enabled.
- Kessel will be used alongside rbac when only enabled for specific users, orgs, or accounts.
make db-migrate-upmake runHit the API:
curl -H "$( ./scripts/header.sh 9999 1111 )" http://localhost:8000/api/content-sources/v1.0/repositories/make openapimake mockThis is completely optional way of running the server that is useful for local development. It rebuilds the project after every change you make, so you always have the most up-to-date server running. To set this up, all you need to do is install the "Air" go tool, here is how. The recommended way is doing:
go install github.com/air-verse/air@latestAfter that, all that needs to be done is just running air, it should automatically use the defined config for this project (.air.toml).
airWhile working on features in the Image Builder frontend that integrate with this service, it can be useful to develop and test those alongside each other locally. To do that there are 2 changes required in the IB FE repo:
- Changing the path to the content sources API config. From which will Redux generate the clients.
api/config/contentSources.ts:schemaFile: '/YOUR_LOCAL_PATH_TO_THIS_REPO/content-sources-backend/api/openapi.json', - Adding a route to the FEC config, which will be picked by the frontend dev proxy.
fec.config.js:['/api/content-sources']: { host: 'http://127.0.0.1:8000' }
Example Git Patch:
diff --git a/api/config/contentSources.ts b/api/config/contentSources.ts
index 7d4db495..32a00e3f 100644
--- a/api/config/contentSources.ts
+++ b/api/config/contentSources.ts
@@ -1,7 +1,7 @@
import type { ConfigFile } from '@rtk-query/codegen-openapi';
const config: ConfigFile = {
- schemaFile: 'https://console.redhat.com/api/content-sources/v1/openapi.json',
+ schemaFile: 'YOUR_LOCAL_PATH_TO_THE_CONTENT_SOURCES_BACKEND_REPO/content-sources-backend/api/openapi.json',
apiFile: '../../src/store/service/emptyContentSourcesApi.ts',
apiImport: 'emptyContentSourcesApi',
outputFile: '../../src/store/service/contentSourcesApi.ts',
diff --git a/fec.config.js b/fec.config.js
index 3767689d..cba37234 100644
--- a/fec.config.js
+++ b/fec.config.js
@@ -102,6 +102,7 @@ module.exports = {
};
}, {}),
}),
+ ['/api/content-sources']: { host: 'http://127.0.0.1:8000' }
},
plugins: plugins,
moduleFederation: {The default configuration file in ./configs/config.yaml.example shows all available config options. Any of these can be overridden with an environment variable. For example "database.name" can be passed in via an environment variable named "DATABASE_NAME".
To use golangci-lint:
make install-golangci-lintmake lint
To use pre-commit linter: make install-pre-commit
| Path | Description |
|---|---|
| api | Openapi docs and doc generation code |
| db/migrations | Database Migrations |
| pkg/api | API Structures that are used for handling data within our API Handlers |
| pkg/config | Config loading and application bootstrapping code |
| pkg/dao | Database Access Object. Abstraction layer that provides an interface and implements it for our default database provider (postgresql). It is separated out for abstraction and easier testing |
| pkg/db | Database connection and migration related code |
| pkg/handler | Methods that directly handle API requests |
| pkg/middleware | Holds all the middleware components created for the service |
| pkg/event | Event message logic. More info here |
| pkg/models | Structs that represent database models (Gorm) |
| pkg/seeds | Code to help seed the database for both development and testing |
| pkg/candlepin_client | Candlepin client |
| pkg/pulp_client | Pulp client |
| pkg/tasks | Tasking system. More info here |
| scripts | Helper scripts for identity header generation and testing |