Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add nextjs skeleton for the ui #11

Merged
merged 24 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/build-frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build Frontend

on:
workflow_call:

jobs:
nextjs-build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ui
steps:
- uses: actions/checkout@v4
- name: Use npm
uses: actions/setup-node@v4

- name: Build frontend
run: |
npm install
npm run build
- name: Upload frontend files
uses: actions/upload-artifact@v4
with:
name: frontend-static-files
path: ui/out
21 changes: 21 additions & 0 deletions .github/workflows/build-gocert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build GoCert

on:
workflow_call:

jobs:
go-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Download frontend files
uses: actions/download-artifact@v4
with:
name: frontend-static-files
path: ui/out
- name: Build
run: go build ./...
30 changes: 30 additions & 0 deletions .github/workflows/build-rock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,37 @@ jobs:
uses: actions/checkout@v4
- uses: canonical/craft-actions/rockcraft-pack@main
id: rockcraft

- name: Install Skopeo
run: |
sudo snap install skopeo --edge --devmode
- name: Import the image to Docker registry
run: |
sudo skopeo --insecure-policy copy oci-archive:${{ steps.rockcraft.outputs.rock }} docker-daemon:gocert:latest
- name: Create files required by GoCert
run: |
printf 'keypath: "/etc/config/key.pem"\ncertpath: "/etc/config/cert.pem"\ndbpath: "/etc/config/certs.db"\nport: 3000\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
run: |
docker run -d -p 3000:3000 --name gocert gocert:latest
- name: Load config
run: |
docker exec gocert /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 restart gocert
- name: Check if GoCert is successfully running
id: test_image
run: |
sleep 30
curl -k https://localhost:3000 2>&1 | grep GoCert

- uses: actions/upload-artifact@v4
if: steps.test_image.outcome == 'success'
with:

name: rock
path: ${{ steps.rockcraft.outputs.rock }}
23 changes: 23 additions & 0 deletions .github/workflows/go-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Lint

on:
workflow_call:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Download frontend files
uses: actions/download-artifact@v4
with:
name: frontend-static-files
path: ui/out
- name: golangci-lint
uses: golangci/golangci-lint-action@v5
with:
version: v1.54
21 changes: 21 additions & 0 deletions .github/workflows/go-vet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Vet

on:
workflow_call:

jobs:
go-vet:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Download frontend files
uses: actions/download-artifact@v4
with:
name: frontend-static-files
path: ui/out
- name: Go vet
run: go vet ./...
76 changes: 18 additions & 58 deletions .github/workflows/main.yml
kayra1 marked this conversation as resolved.
Show resolved Hide resolved
gruyaume marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,30 @@ on:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Build
run: go build ./...

jobs:
unit-test-frontend:
uses: ./.github/workflows/test-frontend.yaml
build-nextjs:
uses: ./.github/workflows/build-frontend.yaml
unit-test-gocert:
needs: [build-nextjs]
uses: ./.github/workflows/test-gocert.yaml
go-vet:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Go vet
run: go vet ./...

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: golangci-lint
uses: golangci/golangci-lint-action@v5
with:
version: v1.54

unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Unit tests
run: go test -cover ./...

needs: [build-nextjs]
uses: ./.github/workflows/go-vet.yaml
go-lint:
needs: [build-nextjs]
uses: ./.github/workflows/go-lint.yaml
build-gocert:
needs: [build-nextjs]
uses: ./.github/workflows/build-gocert.yaml
rock-build:
needs:
- build
- go-vet
- lint
- unit-tests
needs: [build-gocert, unit-test-gocert, go-vet, go-lint]
uses: ./.github/workflows/build-rock.yaml

rock-scan:
if: github.ref_name == 'main'
needs: rock-build
needs: [rock-build]
uses: ./.github/workflows/scan-rock.yaml

publish:
if: github.ref_name == 'main'
needs: [rock-build]
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/test-frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Unit Test Frontend

on:
workflow_call:

jobs:
nextjs-unit-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ui
steps:
- uses: actions/checkout@v4
- name: Use npm
uses: actions/setup-node@v4

- name: Build frontend
run: |
npm install
npm run test
22 changes: 22 additions & 0 deletions .github/workflows/test-gocert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Unit Test GoCert

on:
workflow_call:

jobs:
go-unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Download frontend files
uses: actions/download-artifact@v4
with:
name: frontend-static-files
path: ui/out
- name: Unit tests
run: go test -cover ./...

33 changes: 32 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,35 @@
*.pem
*config.yaml

.DS_Store
.DS_Store

# dependencies
ui/node_modules
ui/.pnp
ui/*.pnp.js
ui/*.yarn/install-state.gz

# testing
ui/coverage

# next.js
ui/.next/
ui/out/

# production
ui/build

# debug
ui/npm-debug.log*
ui/yarn-debug.log*
ui/yarn-error.log*

# local env files
ui/.env*.local

# vercel
ui/.vercel

# typescript
ui/*.tsbuildinfo
ui/next-env.d.ts
24 changes: 19 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,38 @@

## Getting Started

1. Fork the repository on GitHub
2. Clone the forked repository to your local machine
3. Build the project: `go build ./...`
4. Run the project: `./gocert`

1. Install Go and Nodejs
2. Fork the repository on GitHub
3. Clone the forked repository to your local machine
4. Build the frontend: `cd ui && npm build build`
5. Install the project: `go install ./...`
6. Create a `config.yaml` file:
7. Run the project: `gocert -config config.yaml`

Commands for go need to be run from the project directory, and commands for the frontend need to be run from the `ui/` directory
## Testing

### Unit Tests

Go:
```bash
go test ./...
```
Frontend:
```bash
npm run test
```

### Lint

Go:
```bash
golangci-lint run ./...
```
Frontend:
```bash
npm run lint
```

## Container image

Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,18 @@ GoCert is a certificate management tool.
docker pull ghcr.io/canonical/gocert:latest
docker run -it ghcr.io/canonical/gocert:latest
```

## Requirements

GoCert requires 3 files to operate:
* A private key
* A TLS certificate with that private key
* A YAML config file with the required parameters
as an example:

```yaml
keypath: "./key.pem"
certpath: "./cert.pem"
dbpath: "./certs.db"
port: 3000
```
Loading
Loading