diff --git a/.github/workflows/build-rock.yaml b/.github/workflows/build-rock.yaml index 2d83bba..29dc529 100644 --- a/.github/workflows/build-rock.yaml +++ b/.github/workflows/build-rock.yaml @@ -20,7 +20,7 @@ jobs: - name: Create files required by GoCert run: | - printf 'key_path: "/etc/config/key.pem"\ncert_path: "/etc/config/cert.pem"\ndb_path: "/etc/config/certs.db"\nport: 3000\npebble_notifications: true\n' > config.yaml + printf 'key_path: "/etc/gocert/config/key.pem"\ncert_path: "/etc/gocert/config/cert.pem"\ndb_path: "/var/lib/gocert/database/certs.db"\nport: 3000\npebble_notifications: true\n' > config.yaml openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 1 -out cert.pem -subj "/CN=githubaction.example" - name: Run the image @@ -28,10 +28,11 @@ jobs: docker run -d -p 3000:3000 --name gocert gocert:latest - name: Load config run: | - docker exec gocert /usr/bin/pebble mkdir /etc/config - docker cp key.pem gocert:/etc/config/key.pem - docker cp cert.pem gocert:/etc/config/cert.pem - docker cp config.yaml gocert:/etc/config/config.yaml + docker exec gocert /usr/bin/pebble mkdir -p /etc/gocert/config + docker exec gocert /usr/bin/pebble mkdir -p /var/lib/gocert/database + docker cp key.pem gocert:/etc/gocert/config/key.pem + docker cp cert.pem gocert:/etc/gocert/config/cert.pem + docker cp config.yaml gocert:/etc/gocert/config/config.yaml docker restart gocert - name: Check if GoCert frontend is loaded run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6ff020a..28e3350 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,7 @@ # Contributing ## Getting Started +You can build and run the program by following these steps: 1. Install Go and Nodejs 2. Fork the repository on GitHub @@ -11,31 +12,36 @@ 7. Run the project: `gocert -config config.yaml` Commands assume you're running them from the top level git repo directory + ## Testing ### Unit Tests -Go: +Run go unit tests by running: ```bash go test ./... ``` -Frontend: + +Run frontend vitest test suite by running: ```bash -npm run test +npm run test --prefix ui ``` ### Lint -Go: +Run the linter for golang by running: ```bash golangci-lint run ./... ``` -Frontend: +Run the linter for typescript by running: ```bash npm run lint ``` -## Container image +## Creating the Container Image + +We use rockcraft to create OCI images for use in container technologies like docker. +You can create the container and import it into docker by running: ```bash rockcraft pack -v diff --git a/README.md b/README.md index c9f2702..de53e49 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,6 @@ GoCert is a certificate management tool. -## Installation - -```bash -docker pull ghcr.io/canonical/gocert:latest -docker run -it ghcr.io/canonical/gocert:latest -``` - ## Requirements GoCert requires 3 files to operate: @@ -17,7 +10,7 @@ GoCert requires 3 files to operate: * A YAML config file with the required parameters You can generate the cert and the associated key by running: -``` +```bash openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 1 -out cert.pem -subj "/CN=example.com" ``` @@ -36,9 +29,36 @@ The config file requires the following parameters: An example config file may look like: ```yaml -key_path: "./key.pem" -cert_path: "./cert.pem" -db_path: "./certs.db" +key_path: "/etc/gocert/config/key.pem" +cert_path: "/etc/gocert/config/cert.pem" +db_path: "/var/lib/gocert/database/certs.db" port: 3000 pebble_notifications: true -``` \ No newline at end of file +``` + +## Installation + +### From OCI Image + +```bash +# Pull the OCI image from github and run it in docker +docker pull ghcr.io/canonical/gocert:latest +docker run -d --name gocert -p 3000:3000 ghcr.io/canonical/gocert:latest +# Push the 3 required files and restart the workload +docker exec gocert /usr/bin/pebble mkdir -p /etc/gocert/config +docker exec gocert /usr/bin/pebble mkdir -p /var/lib/gocert/database +docker cp key.pem gocert:/etc/gocert/config/key.pem +docker cp cert.pem gocert:/etc/gocert/config/cert.pem +docker cp config.yaml gocert:/etc/gocert/config/config.yaml +docker restart gocert +``` + +### From Source + +go and npm CLI tools need to be installed in order to build gocert from source. +You will need to build the frontend first, and then install gocert with Go. + +```bash +npm install --prefix ui && npm run build --prefix ui && go install ./... +gocert -config ./config.yaml +``` diff --git a/rockcraft.yaml b/rockcraft.yaml index 1732ec5..61ac6ef 100644 --- a/rockcraft.yaml +++ b/rockcraft.yaml @@ -1,7 +1,7 @@ name: gocert base: bare build-base: ubuntu@24.04 -version: '0.0.2' +version: '0.0.3' summary: A certificate management tool description: | A certificate management tool. @@ -12,7 +12,7 @@ platforms: services: gocert: - command: gocert [ -config /etc/config/config.yaml ] + command: gocert [ -config /etc/gocert/config/config.yaml ] override: replace startup: enabled