This is part of a project course in Computer Science for students in their third year at Luleå tekniska universitet.
The project revolves around a already developed Demand-Supply Matching service. Our contribution is the decentralized and RBAC part, using IPFS.
Ludvig Järvi
Anton Follinger
Daniel Hammar
Martin Höglund
Builds a container containing Digiprime and Negotiation Engine.
It also starts a MongoDB server that both applications use. Authentication is handled by Keycloak which is started as well.
An automated build of the container exists on
Docker Hub. To use this replace
digiprime
with norlen/digiprime:latest
in the commands below.
Get the source, the submodules must be cloned as well for the build to be valid.
git clone --recurse-submodules https://github.com/LarsHajdronKolajder/digiprime-container
cd digiprime-container
docker build . -t digiprime # Build container
Instructions to start a development build exist here, currently production
builds are not supported. To use the pre-built image replace digiprime
with
norlen/digiprime:latest
. If the image has been pulled before run
docker image rm norlen/digiprime:latest
to clear it.
The most basic way to run is
docker run -p 3000:3000 \
--env MAPBOX_TOKEN=<your token> \
digiprime
Runs Digiprime which is avaiable at http://localhost:3000
.
To instead run a more complete build with image uploading support, data persistance, and a custom keycloak admin user run
docker run -p 3000:3000 \
--env MAPBOX_TOKEN=<your token> \
--env CLOUDINARY_CLOUD_NAME=<your info> \
--env CLOUDINARY_KEY=<your info> \
--env CLOUDINARY_SECRET=<your info> \
--env APIKEY=<project_api_key> \
--env LEDGER_URL=<your MongoDB url> \
-p 105:105 \
-p 107:107 \
-v mongodb_data:/data/db \
digiprime
Get in contact with me to get the keys to run a proper version.
This starts the Digiprime server on http://localhost:3000
.
Required environment variables:
MAPBOX_TOKEN
: Mapbox API key.SECRET
: Key to encrypt cookies. Default value is thisshouldbeabettersecret
so this should be set to another value for the server to be secure. The way it is set up is that it accepts a comma separated list of secrets, where the first one is used to sign new cookies. This allows for rolling updates of secrets, example new,old
. See express-session for more information.CLOUDINARY_CLOUD_NAME
: Cloudinary cloud name.CLOUDINARY_KEY
: Cloudinary API key.CLOUDINARY_SECRET
: Cloudinary secret.Configurable values:
BASE_URL
: If the application is served on a subpath, this controls which one, default: ""
.NODE_ENV
: defaults to development
, can optionally be set to production
to hide debug information such as stack traces.AUTH_BASE_URL
: default path to the auth server.For completeness, the other environent variables are shown here but they should not be changed.
DB_URL
: Database URL for Digiprime, can be set to use another database.PORT
: Port to launch Digiprime. However, the image only exposes port 3000
so leave this alone.DATABASE_URL
: Database URL for Negotiation Engine, can be set to use another database.LEDGER_URL
: MongoDB database URL for the Ledger, use your own.To keep data between runs docker volumes should be used.
To persist MongoDB mount /data/db
which is where Mongo stores the data.
Our RBAC system is built on top of an existing RBAC system, which couldn't be modified. This led to the development of our system, featuring a simplified visual frontend. While the frontend was simple, the backend was especially developt to seamlessly integrate with the pre-existing RBAC system, ensuring that the vital controls and checks will work.
User login credentials will be securely stored in MongoDB. Initially, certain information will only be modifiable through direct database access, such as role and seller.
Setting up your own MongoDB cloud server is required for the Ledger to work fully.
Example MongoDB structure
DATABASE NAME
COLLECTION NAME
The required MongoDB structure is:
Users
ID
SignatureID
Signature
username
: Represents the account holder's username on the website.password
: Encrypted password used for account authentication.role
: Defines the user's role, with options including sel for sellers, dev for developers, and bro for brokers.sel
: This is the role for accounts that can sell.dev
: This is just a developer account.bro
: This is the role of a broker that let you sell for other accountsseller
: Specific to broker accounts, indicating the sellers they are authorized to represent.When the user access the new offer
page they will have to fill out the BatteryID
, when this is done and the user press Hämta API (fetch API) they will be promted with the login system. Where inputs are seperated with :
login
: Represents the command that log the user into the account.username
: Represents the account holder's username on the website.password
: Pssword used for account authentication.signup
: Represents the command that create an account.username
: Represents the new accounts username on the website.password
: Pssword used for account authentication.To enable users to create an offer, they must log into an account with the necessary selling rights. Additionally, users must provide the site with a BatteryID
that they own. If the BatteryID
does not exist in the database, it will be created and linked to the logged-in user's account.
docket network create my-network
, this my-network
will be the network that you will join together the Digiprime container, Kubo container and Rest API.--network my_network
to have them accessable within all three docker containersdocker --version
in CLI../Decentralized/IPFS
its two folders ipfs_staging
and ipfs_data
that are created, if not create them.docker pull ipfs/kubo
docker run -d --name ipfs_host --network my_network \ -v ~/dev/github/D0020E/Decentralized/IPFS/ipfs_staging:/export \ -v ~/dev/github/D0020E/Decentralized/IPFS/ipfs_data:/data/ipfs \ -p 4001:4001 -p 4001:4001/udp -p 127.0.0.1:8080:8080 -p 127.0.0.1:5001:5001 \ ipfs/kubo:latest
and replace the paths with your actual paths to the ipfs_staging
and ipfs_data
docker logs -f ipfs_host
or inside Docker Desktop, should look like the image More info can be found at either https://docs.ipfs.tech/install/run-ipfs-inside-docker/#set-up or https://docs.ipfs.tech/how-to/troubleshooting/
npm install
inside Decentralized
folder to get everthing and start with npm start
to make nodemon running.http://ip_addr:port/getPeers
(this will also check Kubos connectivity to other peers within the IPFS network)docker run -p 3009:3009 -d --name ipfs_api --network testing ipfs_api
for Express Rest APIdocker run -d --name ipfs_host --network testing -v ~/dev/github/D0020E/Decentralized/IPFS/ipfs_staging:/export -v ~/dev/github/D0020E/Decentralized/IPFS/ipfs_data:/data/ipfs -p 4001:4001 -p 4001:4001/udp -p 127.0.0.1:8080:8080 -p 127.0.0.1:5001:5001 ipfs/kubo:latest
for Kubo RPC imagedocker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container_name_or_id>
or you can see whats connected to the network by running docker network inspect my_network
to see information regarding the containers currently connected to your docker network.Digiprime/config.js
here you can change the IPFS_URL
to match the IP you get and it gets updated everywhere.docker logs -f ipfs_api
or what you called your ipfs_api (Rest API that communicated with IPFS Kubo) to get the link to the http for the specific CID you just uploaded.
Inside Digiprime/public/javascript/apiButton.js
and Digiprime/public/javascript/ownerChange.js
you need to MANUALLY change the const for the URLs if they are changed otherwise webpack needs to be installed & configurated (since its client-side code).
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.