mirror of
https://github.com/Lakr233/GitLab-License-Generator.git
synced 2026-01-30 11:55:35 +02:00
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
langs/
|
||||||
|
README.md
|
||||||
|
LICENSE
|
||||||
|
.github/
|
||||||
|
Dockerfile
|
||||||
|
.*ignore
|
||||||
47
.github/workflows/docker-image.yml
vendored
Normal file
47
.github/workflows/docker-image.yml
vendored
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# This workflow uses actions that are not certified by GitHub.
|
||||||
|
# They are provided by a third-party and are governed by
|
||||||
|
# separate terms of service, privacy policy, and support
|
||||||
|
# documentation.
|
||||||
|
|
||||||
|
# GitHub recommends pinning actions to a commit SHA.
|
||||||
|
# To get a newer version, you will need to update the SHA.
|
||||||
|
# You can also reference a tag or branch, but the action may change without warning.
|
||||||
|
|
||||||
|
name: Publish Container to Github at dev
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'main'
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Log in to the Container registry
|
||||||
|
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
15
Dockerfile
Normal file
15
Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
FROM ruby:bookworm
|
||||||
|
WORKDIR /license-generator
|
||||||
|
COPY ./ ./
|
||||||
|
RUN <<EOF
|
||||||
|
gem install gitlab-license
|
||||||
|
EOF
|
||||||
|
VOLUME /license-generator/build
|
||||||
|
ENV LICENSE_NAME="Tim Cook"
|
||||||
|
ENV LICENSE_COMPANY="Apple Computer, Inc."
|
||||||
|
ENV LICENSE_EMAIL="tcook@apple.com"
|
||||||
|
ENV LICENSE_PLAN="ultimate"
|
||||||
|
ENV LICENSE_USER_COUNT="2147483647"
|
||||||
|
ENV LICENSE_EXPIRE_YEAR="2500"
|
||||||
|
|
||||||
|
CMD [ "./make.sh" ]
|
||||||
54
README.md
54
README.md
@@ -32,25 +32,64 @@ Features are extracted from an object filled with constants. The most comprehens
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Prerequisites
|
### Using Docker image (Zero setup)
|
||||||
|
|
||||||
|
Using this method license files are generated under `./license` directory
|
||||||
|
> Please note that in standard docker installations, owner of the files generated in license directory will be root
|
||||||
|
|
||||||
|
#### Method (1): Pull image
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --rm -it \
|
||||||
|
-v "./license:/license-generator/build" \
|
||||||
|
-e LICENSE_NAME="Tim Cook" \
|
||||||
|
-e LICENSE_COMPANY="Apple Computer, Inc." \
|
||||||
|
-e LICENSE_EMAIL="tcook@apple.com" \
|
||||||
|
-e LICENSE_PLAN="ultimate" \
|
||||||
|
-e LICENSE_USER_COUNT="2147483647" \
|
||||||
|
-e LICENSE_EXPIRE_YEAR="2500" \
|
||||||
|
ghcr.io/lakr233/gitlab-license-generator:main
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Method (2): Build image
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/Lakr233/GitLab-License-Generator.git
|
||||||
|
docker build GitLab-License-Generator -t gitlab-license-generator:main
|
||||||
|
docker run --rm -it \
|
||||||
|
-v "./license:/license-generator/build" \
|
||||||
|
-e LICENSE_NAME="Tim Cook" \
|
||||||
|
-e LICENSE_COMPANY="Apple Computer, Inc." \
|
||||||
|
-e LICENSE_EMAIL="tcook@apple.com" \
|
||||||
|
-e LICENSE_PLAN="ultimate" \
|
||||||
|
-e LICENSE_USER_COUNT="2147483647" \
|
||||||
|
-e LICENSE_EXPIRE_YEAR="2500" \
|
||||||
|
gitlab-license-generator:main
|
||||||
|
```
|
||||||
|
|
||||||
|
### Manual: Prerequisites
|
||||||
|
|
||||||
Before starting, ensure your environment is properly configured.
|
Before starting, ensure your environment is properly configured.
|
||||||
|
|
||||||
#### 1. Install Ruby and gem
|
#### 1. Install Ruby and gem
|
||||||
|
|
||||||
To run this project, you need **Ruby** and the **gem** package manager.
|
To run this project, you need **Ruby** and the **gem** package manager.
|
||||||
|
|
||||||
- **On Linux (Ubuntu/Debian)**:
|
- **On Linux (Ubuntu/Debian)**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt install ruby-full
|
sudo apt install ruby-full
|
||||||
```
|
```
|
||||||
|
|
||||||
- **On macOS** (via Homebrew):
|
- **On macOS** (via Homebrew):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
brew install ruby
|
brew install ruby
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 2. Install Bundler and necessary gems
|
#### 2. Install Bundler and necessary gems
|
||||||
|
|
||||||
After installing Ruby, you need to install **Bundler** to manage Ruby dependencies.
|
After installing Ruby, you need to install **Bundler** to manage Ruby dependencies.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -58,6 +97,7 @@ gem install bundler
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### 3. Install the `gitlab-license` gem
|
#### 3. Install the `gitlab-license` gem
|
||||||
|
|
||||||
The project requires the `gitlab-license` gem, which will be automatically downloaded and used by the script.
|
The project requires the `gitlab-license` gem, which will be automatically downloaded and used by the script.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -67,6 +107,7 @@ gem install gitlab-license
|
|||||||
### Steps to Generate the GitLab License
|
### Steps to Generate the GitLab License
|
||||||
|
|
||||||
#### 1. Clone the project repository
|
#### 1. Clone the project repository
|
||||||
|
|
||||||
Clone this project to your local machine.
|
Clone this project to your local machine.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -75,6 +116,7 @@ cd GitLab-License-Generator
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### 2. Run the `make.sh` script
|
#### 2. Run the `make.sh` script
|
||||||
|
|
||||||
Once all the prerequisites are met, run the script:
|
Once all the prerequisites are met, run the script:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -82,6 +124,7 @@ Once all the prerequisites are met, run the script:
|
|||||||
```
|
```
|
||||||
|
|
||||||
The script will perform the following actions:
|
The script will perform the following actions:
|
||||||
|
|
||||||
- Download and extract the `gitlab-license` gem.
|
- Download and extract the `gitlab-license` gem.
|
||||||
- Copy and modify the required files.
|
- Copy and modify the required files.
|
||||||
- Clone the GitLab source code from GitLab.com.
|
- Clone the GitLab source code from GitLab.com.
|
||||||
@@ -89,9 +132,11 @@ The script will perform the following actions:
|
|||||||
- Generate a GitLab license.
|
- Generate a GitLab license.
|
||||||
|
|
||||||
#### 3. Replace the public key in GitLab
|
#### 3. Replace the public key in GitLab
|
||||||
|
|
||||||
The script generates a public key located in `build/public.key`. You need to replace GitLab’s existing public key with this newly generated one to ensure the license is accepted.
|
The script generates a public key located in `build/public.key`. You need to replace GitLab’s existing public key with this newly generated one to ensure the license is accepted.
|
||||||
|
|
||||||
- **If GitLab is installed on your server**:
|
- **If GitLab is installed on your server**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo cp ./build/public.key /opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub
|
sudo cp ./build/public.key /opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub
|
||||||
sudo gitlab-ctl reconfigure
|
sudo gitlab-ctl reconfigure
|
||||||
@@ -107,12 +152,14 @@ The script generates a public key located in `build/public.key`. You need to rep
|
|||||||
```
|
```
|
||||||
|
|
||||||
Then restart the container:
|
Then restart the container:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker-compose down
|
docker-compose down
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 4. Install the license in GitLab
|
#### 4. Install the license in GitLab
|
||||||
|
|
||||||
Once the public key is replaced, log in to GitLab’s admin interface to install the generated license.
|
Once the public key is replaced, log in to GitLab’s admin interface to install the generated license.
|
||||||
|
|
||||||
1. Log in to GitLab as an administrator.
|
1. Log in to GitLab as an administrator.
|
||||||
@@ -121,24 +168,29 @@ Once the public key is replaced, log in to GitLab’s admin interface to install
|
|||||||
4. Check the **Terms of Service** checkbox and click **Add License**.
|
4. Check the **Terms of Service** checkbox and click **Add License**.
|
||||||
|
|
||||||
If necessary, you can directly access the license upload page via:
|
If necessary, you can directly access the license upload page via:
|
||||||
|
|
||||||
```
|
```
|
||||||
<YourGitLabURL>/admin/license/new
|
<YourGitLabURL>/admin/license/new
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 5. Disable Service Ping (optional)
|
#### 5. Disable Service Ping (optional)
|
||||||
|
|
||||||
If you want to disable GitLab’s usage data collection (Service Ping), modify GitLab’s configuration file:
|
If you want to disable GitLab’s usage data collection (Service Ping), modify GitLab’s configuration file:
|
||||||
|
|
||||||
- Open the configuration file:
|
- Open the configuration file:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo nano /etc/gitlab/gitlab.rb
|
sudo nano /etc/gitlab/gitlab.rb
|
||||||
```
|
```
|
||||||
|
|
||||||
- Add the following line:
|
- Add the following line:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
gitlab_rails['usage_ping_enabled'] = false
|
gitlab_rails['usage_ping_enabled'] = false
|
||||||
```
|
```
|
||||||
|
|
||||||
- Reconfigure and restart GitLab:
|
- Reconfigure and restart GitLab:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo gitlab-ctl reconfigure
|
sudo gitlab-ctl reconfigure
|
||||||
sudo gitlab-ctl restart
|
sudo gitlab-ctl restart
|
||||||
|
|||||||
62
make.sh
62
make.sh
@@ -17,7 +17,7 @@ if [ ! -f ".root" ]; then
|
|||||||
fi
|
fi
|
||||||
WORKING_DIR=$(pwd)
|
WORKING_DIR=$(pwd)
|
||||||
|
|
||||||
mkdir temp 2> /dev/null || true
|
mkdir temp 2>/dev/null || true
|
||||||
|
|
||||||
echo "[*] fetching ruby gem version..."
|
echo "[*] fetching ruby gem version..."
|
||||||
RB_GEM_NAME="gitlab-license"
|
RB_GEM_NAME="gitlab-license"
|
||||||
@@ -30,14 +30,14 @@ while IFS= read -r line; do
|
|||||||
RB_GEM_VERSION=${RB_GEM_VERSION%")"}
|
RB_GEM_VERSION=${RB_GEM_VERSION%")"}
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done <<< "$RB_GEM_LIST_OUTPUT"
|
done <<<"$RB_GEM_LIST_OUTPUT"
|
||||||
|
|
||||||
echo "[*] gitlab-license version: $RB_GEM_VERSION"
|
echo "[*] gitlab-license version: $RB_GEM_VERSION"
|
||||||
RB_GEM_DOWNLOAD_URL="https://rubygems.org/downloads/gitlab-license-$RB_GEM_VERSION.gem"
|
RB_GEM_DOWNLOAD_URL="https://rubygems.org/downloads/gitlab-license-$RB_GEM_VERSION.gem"
|
||||||
RB_GEM_DOWNLOAD_PATH=$(pwd)/temp/gem/gitlab-license.gem
|
RB_GEM_DOWNLOAD_PATH=$(pwd)/temp/gem/gitlab-license.gem
|
||||||
mkdir -p $(dirname $RB_GEM_DOWNLOAD_PATH)
|
mkdir -p "$(dirname "$RB_GEM_DOWNLOAD_PATH")"
|
||||||
curl -L $RB_GEM_DOWNLOAD_URL -o $RB_GEM_DOWNLOAD_PATH 1> /dev/null 2> /dev/null
|
curl -L "$RB_GEM_DOWNLOAD_URL" -o "$RB_GEM_DOWNLOAD_PATH" 1>/dev/null 2>/dev/null
|
||||||
pushd $(dirname $RB_GEM_DOWNLOAD_PATH) > /dev/null
|
pushd "$(dirname "$RB_GEM_DOWNLOAD_PATH")" >/dev/null
|
||||||
tar -xf gitlab-license.gem
|
tar -xf gitlab-license.gem
|
||||||
tar -xf data.tar.gz
|
tar -xf data.tar.gz
|
||||||
|
|
||||||
@@ -47,31 +47,34 @@ if [ ! -f "./lib/gitlab/license.rb" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "[*] copying gem..."
|
echo "[*] copying gem..."
|
||||||
rm -rf "$WORKING_DIR/lib" || true
|
rm -rf "${WORKING_DIR:?}/lib" || true
|
||||||
mkdir -p "$WORKING_DIR/lib"
|
mkdir -p "$WORKING_DIR/lib"
|
||||||
cp -r ./lib/gitlab/* $WORKING_DIR/lib
|
cp -r ./lib/gitlab/* "$WORKING_DIR/lib"
|
||||||
popd > /dev/null
|
popd >/dev/null
|
||||||
|
|
||||||
pushd lib > /dev/null
|
pushd lib >/dev/null
|
||||||
echo "[*] patching lib requirements gem..."
|
echo "[*] patching lib requirements gem..."
|
||||||
|
|
||||||
# Determine the operating system
|
# Determine the operating system
|
||||||
OS_TYPE="$(uname -s)"
|
OS_TYPE="$(uname -s)"
|
||||||
|
|
||||||
case "$OS_TYPE" in
|
case "$OS_TYPE" in
|
||||||
Linux*)
|
Linux*)
|
||||||
sed_i_cmd="sed -i";;
|
sed_i_cmd="sed -i"
|
||||||
Darwin*)
|
;;
|
||||||
sed_i_cmd="sed -i ''";;
|
Darwin*)
|
||||||
*)
|
sed_i_cmd="sed -i ''"
|
||||||
echo "Unsupported OS: $OS_TYPE";
|
;;
|
||||||
exit 1;;
|
*)
|
||||||
|
echo "Unsupported OS: $OS_TYPE"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# replace `require 'gitlab/license/` with `require 'license/` to make it work
|
# replace `require 'gitlab/license/` with `require 'license/` to make it work
|
||||||
find . -type f -exec $sed_i_cmd 's/require '\''gitlab\/license\//require_relative '\''license\//g' {} \;
|
find . -type f -exec $sed_i_cmd 's/require '\''gitlab\/license\//require_relative '\''license\//g' {} \;
|
||||||
|
|
||||||
popd > /dev/null
|
popd >/dev/null
|
||||||
|
|
||||||
echo "[*] updated gem"
|
echo "[*] updated gem"
|
||||||
|
|
||||||
@@ -82,22 +85,21 @@ mkdir -p "$GITLAB_SOURCE_CODE_DIR"
|
|||||||
echo "[*] downloading features file..."
|
echo "[*] downloading features file..."
|
||||||
curl -L https://gitlab.com/gitlab-org/gitlab/-/raw/master/ee/app/models/gitlab_subscriptions/features.rb?inline=false -o "$GITLAB_SOURCE_CODE_DIR/features.rb"
|
curl -L https://gitlab.com/gitlab-org/gitlab/-/raw/master/ee/app/models/gitlab_subscriptions/features.rb?inline=false -o "$GITLAB_SOURCE_CODE_DIR/features.rb"
|
||||||
|
|
||||||
|
|
||||||
BUILD_DIR=$(pwd)/build
|
BUILD_DIR=$(pwd)/build
|
||||||
mkdir -p $BUILD_DIR
|
mkdir -p "$BUILD_DIR"
|
||||||
|
|
||||||
echo "[*] scanning features..."
|
echo "[*] scanning features..."
|
||||||
FEATURE_LIST_FILE=$BUILD_DIR/features.json
|
FEATURE_LIST_FILE=$BUILD_DIR/features.json
|
||||||
rm -f $FEATURE_LIST_FILE || true
|
rm -f "${FEATURE_LIST_FILE:?}" || true
|
||||||
./src/scan.features.rb \
|
./src/scan.features.rb \
|
||||||
-o $FEATURE_LIST_FILE \
|
-o "$FEATURE_LIST_FILE" \
|
||||||
-f "$GITLAB_SOURCE_CODE_DIR/features.rb"
|
-f "$GITLAB_SOURCE_CODE_DIR/features.rb"
|
||||||
|
|
||||||
echo "[*] generating key pair..."
|
echo "[*] generating key pair..."
|
||||||
PUBLIC_KEY_FILE=$BUILD_DIR/public.key
|
PUBLIC_KEY_FILE=$BUILD_DIR/public.key
|
||||||
PRIVATE_KEY_FILE=$BUILD_DIR/private.key
|
PRIVATE_KEY_FILE=$BUILD_DIR/private.key
|
||||||
cp -f ./keys/public.key $PUBLIC_KEY_FILE
|
cp -f ./keys/public.key "$PUBLIC_KEY_FILE"
|
||||||
cp -f ./keys/private.key $PRIVATE_KEY_FILE
|
cp -f ./keys/private.key "$PRIVATE_KEY_FILE"
|
||||||
|
|
||||||
# execute following command to generate new keys
|
# execute following command to generate new keys
|
||||||
# ./src/generator.keys.rb \
|
# ./src/generator.keys.rb \
|
||||||
@@ -109,16 +111,16 @@ LICENSE_FILE=$BUILD_DIR/result.gitlab-license
|
|||||||
LICENSE_JSON_FILE=$BUILD_DIR/license.json
|
LICENSE_JSON_FILE=$BUILD_DIR/license.json
|
||||||
|
|
||||||
./src/generator.license.rb \
|
./src/generator.license.rb \
|
||||||
-f $FEATURE_LIST_FILE \
|
-f "$FEATURE_LIST_FILE" \
|
||||||
--public-key $PUBLIC_KEY_FILE \
|
--public-key "$PUBLIC_KEY_FILE" \
|
||||||
--private-key $PRIVATE_KEY_FILE \
|
--private-key "$PRIVATE_KEY_FILE" \
|
||||||
-o $LICENSE_FILE \
|
-o "$LICENSE_FILE" \
|
||||||
--license-name "$LICENSE_NAME" \
|
--license-name "$LICENSE_NAME" \
|
||||||
--license-company "$LICENSE_COMPANY" \
|
--license-company "$LICENSE_COMPANY" \
|
||||||
--license-email "$LICENSE_EMAIL" \
|
--license-email "$LICENSE_EMAIL" \
|
||||||
--license-plan "$LICENSE_PLAN" \
|
--license-plan "$LICENSE_PLAN" \
|
||||||
--license-user-count "$LICENSE_USER_COUNT" \
|
--license-user-count "$LICENSE_USER_COUNT" \
|
||||||
--license-expire-year "$LICENSE_EXPIRE_YEAR" \
|
--license-expire-year "$LICENSE_EXPIRE_YEAR" \
|
||||||
--plain-license $LICENSE_JSON_FILE
|
--plain-license "$LICENSE_JSON_FILE"
|
||||||
|
|
||||||
echo "[*] done $(basename $0)"
|
echo "[*] done $(basename "$0")"
|
||||||
|
|||||||
Reference in New Issue
Block a user