Skip to content

Commit

Permalink
Merge pull request #4 from BenjaminFourmaux/Doc-V1
Browse files Browse the repository at this point in the history
Prepare Doc for V1
  • Loading branch information
BenjaminFourmaux authored Apr 15, 2024
2 parents 7cb6d2d + e5b514d commit edc5a48
Show file tree
Hide file tree
Showing 10 changed files with 640 additions and 113 deletions.
85 changes: 85 additions & 0 deletions .github/workflows/build_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

# Usage
# run this command at the root of the project

# Welcome message
echo "Pipeline build packages"

# Get args
if [ -z "$1" ]; then
release_version="1.0.0"
else
release_version=$1
fi

if [ -z "$2" ]; then
build_dir="../.build"
else
build_dir=$2
fi

if [ -z "$3" ]; then
release_name="Helm-Registry"
else
release_name=$3
fi

# Release prefix
release_prefix="${release_name}-${release_version}"
echo "Release prefix: ${release_prefix}"

# Set location to the backend file
cd backend

# Build for Windows
echo "Building for Windows..."
GOOS=windows GOARCH=amd64 go build -o "${build_dir}/${release_prefix}_windows.exe"
if [ $? -eq 0 ]; then
echo "Build for Windows successful"
echo "> Artifact build in ${build_dir}/${release_prefix}_windows.exe"
else
echo "Failed to build for Windows"
exit 1
fi

# Build for Linux
echo "Building for Linux..."
set CGO_ENABLED=1
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o "${build_dir}/${release_name,,}"
if [ $? -eq 0 ]; then
echo "Build for Linux successful"
echo "> Artifact build in ${build_dir}/${release_name,,}"

# Zip
tar -czvf "${build_dir}/${release_prefix}_linux.tar.gz" -C "${build_dir}" "${release_name,,}"
else
echo "Failed to build for Linux"
exit 1
fi

# Build for Docker
echo "Building Docker image..."
docker build -t "${release_name,,}:${release_version}" .
if [ $? -eq 0 ]; then
echo "Docker image build successful"

# Save Docker image
echo "Save Docker image..."
docker save "${release_name,,}:${release_version}" -o "${build_dir}/${release_prefix}_docker.tar"

if [ $? -eq 0 ]; then
echo "Docker image saved"
echo "> Artifact build in ${build_dir}/${release_prefix}_docker.tar"
exit 0
else
echo "Failed to save Docker image"
exit 1
fi

else
echo "Failed to build Docker image"
exit 1
fi

echo "All builds completed successfully"
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
.idea
# JetBrain IDE config
.idea

# Obsidia IDE config
.obsidian

# Build articfacts directory
.build
34 changes: 29 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
# Changelog
[![](https://badgen.net/github/tag/BenjaminFourmaux/{{repository.name}}?cache=600)]() [![](https://badgen.net/github/release/BenjaminFourmaux/{{repository.name}}?cache=600)]() [![](https://badgen.net/github/tags/BenjaminFourmaux/{{repository.name}})]()
--
## V.1.0 - First one
[![](https://badgen.net/github/tag/BenjaminFourmaux/Helm-Registry?cache=600)]() [![](https://badgen.net/github/release/BenjaminFourmaux/Helm-Registry?cache=600)]() [![](https://badgen.net/github/tags/BenjaminFourmaux/Helm-Registry)]()

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

---

## V.1.0 - Basics features requirement
### Added
### Changed
### Removed
- **Charts Discovery**
- The Charts Directory is the Single Source of Truth (SSoT) !
- Implement Charts Directory Watcher, that listen when a action (create a file, remove file, modified file...) is dispense.
- **API**
- Endpoint `/`, the home page to get this registry informations (in YAML output format).
- Endpoint `/index.yaml`, the index of charts in this registry. Is a Helm requirement.
- Endpoint `/charts/`, bind with the Charts Directory. Able to get charts archives.
- **Database**
- SQLite Database to store registered Helm Charts and registry about the registry.
- Database management class `Class/Database/Database/Database.go`.
- Classes for `SELECT`, `INSERT`, `UPDATE` and `DELETE` queries.
- Table `registry` which contains all informations about this registry (name, version, maintainer, tags...).
- Table `charts` which contains all informations about all registered charts (in charts directory).
- **Docker**
- Dockerfile : For build a Docker image of the app.
- Docker compose file : For deploying a registry container with compose.
- **Env**
- Manage env var
- **Misc**
- Get OS environment that run this app (Windows, Linux or Docker) and adapte the comportement
89 changes: 84 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,89 @@ There are 2 parts :
- **Frontend** : Build in ReactJS, for Web UI to manage Helm registry

These parts are Docker images, that you use and deploy him in Docker env.

![](architecture.png)

## Features :sparkles:
- Expose `index.yaml` file and `/charts/*.tgz` charts, according to the [Helm registry requirement](https://helm.sh/docs/topics/chart_repository/)
- **Chart Discovery** : Automatically insert/update/delete charts from the charts directory, in database and update the `index.yaml` file.
- **Chart Discovery** : Browse all `.tgz` files and open them to search file `Chart.yaml` inside, extract chart information and send this to the Database and updating `index.yaml` file.
- Customize the home page of the registry (`/`) with a CRD (`helm`) to describe your registry.

### Environment
- [x] On **Windows**
- [x] On **Linux**
- [x] On **Docker**, use the Docker image to deploy this registry on Docker env. You can use a Docker Compose file to deploy this (an [exemple here](docker-compose.yaml))

### Helm commands coverage
![Static Badge](https://img.shields.io/badge/67%25-covrage?style=for-the-badge&logo=helm&label=Commands%20covrage&color=orange)

The Helm client-side commands that you can use with this registry. Doc [here](https://helm.sh/docs/helm/helm_repo/)
- [x] **helm repo add** : Able to add the registry in your Helm client
- [x] **helm repo update** : Update your client copy of your distant registry to be able to pull chart
- [x] **helm search repo** : Able to list all charts available in your registry
- [x] **helm pull** : Able to pull a chart from your registry to use it
- [ ] **helm push** : Currently unable to push a chart into this registry (maybe in newer version)
- [ ] **credentials flags** (--pass-credentials, --password, --password-stdin and --username) : Currently any credential is required to use the registry (_in coming in newer version_)

## Get stated :rocket:

### Install from source code
> You need to have the corresponding Golang version installed.
Download the zip or clone this repository, and go to to `backend` folder. Execute these following commands

Download packages :
```bash
go mod download
```

Run the app :
```bash
go run .
```

### Install on Linux
Download the file `Helm-Registry-x.x.x_linux.tar.gz` from release artifacts in your Linux system.
Uncompressed the archive with the following command :
```bash
tar -xzvf Helm-Registry-1.0.0_linux.tar.gz
```

> I recommend to uncompressed this archive in the path `/app/helm-registry/`. It's better to regroup all files in a same folder.
Adding permissions to execute the app
```bash
chmod +x helm-registry
```

And launch the app
```bash
./helm-registry
```

After first app launch, that created some files behind the app (like sqlite db and `index.yaml`) and create (if not exist) charts directory (default: /usr/helm-registry/charts).

### Install on Windows
Download the .exe file from release artifacts and place it wherever you want. Execute the file and voilà !
That create `registry.db` and `index.yaml`. So it is better to place it in a specific folder.

### Install on Docker
From image archive .tar, load the image :
```bash
docker load -i Helm-Registry-x.x.x_docker.tar
```

Run Docker container :
```bash
docker run helm-registry:x.x.x
```

With flags :
```bash
docker run -p 8080 --mount type=volume,target=/usr/helm-registry/charts,dst=/charts helm-registry:x.x.x
```

### Environment Variables
It exists some environment variables to customize the registry.

Expand All @@ -30,11 +109,11 @@ It exists some environment variables to customize the registry.
| `CHARTS_DIR` | Path of charts directory location. By default : for Linux `/usr/helm-registry/charts`, Windows `%USERPROFILE%\Documents\helm-registry\charts` |

## Version
[![](https://badgen.net/github/tag/BenjaminFourmaux/helm-registry?cache=600)](https://github.com/BenjaminFourmauxhelm-registry/tags) [![](https://badgen.net/github/release/BenjaminFourmaux/helm-registry?cache=600)](https://github.com/BenjaminFourmaux/helm-registry/releases)
- [coming soon][v1] First API version with basic actions
[![](https://badgen.net/github/tag/BenjaminFourmaux/Helm-Registry?cache=600)](https://github.com/BenjaminFourmaux/Helm-Registry/tags) [![](https://badgen.net/github/release/BenjaminFourmaux/Helm-Registry?cache=600)](https://github.com/BenjaminFourmaux/Helm-Registry/releases)
- [v1] First API version with basic actions for a simple usage. According to the Helm repository requirements

## Contributors 👪
[![](https://badgen.net/github/contributors/BenjaminFourmaux/helm-registry)](https://github.com/BenjaminFourmaux/helm-registry/graphs/contributors)
## Contributors 👥
[![](https://badgen.net/github/contributors/BenjaminFourmaux/Helm-Registry)](https://github.com/BenjaminFourmaux/Helm-Registry/graphs/contributors)
- :crown: [Benjamin Fourmaux](https://github.com/BenjaminFourmaux)

## Licence ⚖️
Expand All @@ -46,4 +125,4 @@ You can:

You must **Mention** the © Copyright if you use and modified code for your own profit. Thank you

© 2004 - Benjamin Fourmaux -- Beruet - All right reserved
© 2024 - Benjamin Fourmaux -- Beruet - All right reserved
409 changes: 409 additions & 0 deletions app-architecture.drawio

Large diffs are not rendered by default.

87 changes: 0 additions & 87 deletions architecture.drawio

This file was deleted.

Binary file modified architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions backend/Class/Logger/Logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ func Raise(err string) {
func Separator() {
println("----------------------------------")
}

// Welcome to Display a welcome message at the start
func Welcome() {
println("------{ Welcome on Helm Registry }------")
println("Ahoy!")
println("A simple Helm chart registry")
println()
println("Version :", "1.0.0")
println()
Info("App is going to start ...")
}
27 changes: 13 additions & 14 deletions backend/Class/Utils/env/Environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
// Using var instead of os.getEnv() for improve security against EnvVarInjection
// That store en var in the program memory instead of each time calling os.getEnv and get changed value
var (
IS_DOCKER bool // IS_DOCKER Env var - True if on Docker env, False if is on Windows or Linux
INDEX_FILE_PATH string // INDEX_FILE_PATH Env var - Path to the index.yaml file
CHARTS_DIR string // REPOSITORY_DIR Env var - Path to the charts folder
REGISTRY_NAME string // REGISTRY_NAME Env var - Name of this registry
Expand All @@ -21,8 +20,8 @@ var (
)

func SetupEnv() {
// Get the running env (Docker or not)
isDocker := IsDocker()
// Get the running env
getOSPlatform()

// Get Env vars and if not declared, init it with default value
if os.Getenv("INDEX_FILE_PATH") == "" {
Expand All @@ -33,15 +32,13 @@ func SetupEnv() {
if runtime.GOOS == "windows" {
userDocs := os.Getenv("USERPROFILE") + "\\Documents\\helm-registry\\charts"
_ = os.Setenv("CHARTS_DIR", userDocs)
//_ = os.Setenv("CHARTS_DIR", "../test/chart")

} else { // Linux and Docker platforms
_ = os.Setenv("CHARTS_DIR", "/usr/helm-registry/charts")
}
}

// Save env var change after permutation in class properties
IS_DOCKER = isDocker
INDEX_FILE_PATH = os.Getenv("INDEX_FILE_PATH")
CHARTS_DIR = os.Getenv("CHARTS_DIR")
REGISTRY_NAME = os.Getenv("REGISTRY_NAME")
Expand All @@ -61,18 +58,20 @@ func SetupEnv() {
} else {
Logger.Success("Creating CHARTS_DIR on : " + CHARTS_DIR)
}
} else {
Logger.Success("Charts Directory is on : " + CHARTS_DIR)
}
}

func IsDocker() bool {
_, err := os.Stat("/.dockerenv")
if err == nil {
Logger.Info("App running on Docker")
return true
} else if os.IsNotExist(err) {
Logger.Info("App not running on Docker")
return false
func getOSPlatform() {
if runtime.GOOS == "windows" {
Logger.Info("OS Platform : Windows")
} else {
return false
_, err := os.Stat("/.dockerenv")
if os.IsNotExist(err) {
Logger.Info("OS Platform : Linux")
} else {
Logger.Info("OS Platform : Docker")
}
}
}
2 changes: 1 addition & 1 deletion backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func main() {
Logger.Info("Helm Registry - Started")
Logger.Welcome()

// Setup env
env.SetupEnv()
Expand Down

0 comments on commit edc5a48

Please sign in to comment.