diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..8785de2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +langs/ +README.md +LICENSE +.github/ +Dockerfile +.*ignore diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 000000000..915761c --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -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 }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..9aa7585 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM ruby:bookworm +WORKDIR /license-generator +COPY ./ ./ +RUN < 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. #### 1. Install Ruby and gem + To run this project, you need **Ruby** and the **gem** package manager. - **On Linux (Ubuntu/Debian)**: + ```bash sudo apt update sudo apt install ruby-full ``` - **On macOS** (via Homebrew): + ```bash brew install ruby ``` #### 2. Install Bundler and necessary gems + After installing Ruby, you need to install **Bundler** to manage Ruby dependencies. ```bash @@ -58,6 +97,7 @@ gem install bundler ``` #### 3. Install the `gitlab-license` gem + The project requires the `gitlab-license` gem, which will be automatically downloaded and used by the script. ```bash @@ -67,6 +107,7 @@ gem install gitlab-license ### Steps to Generate the GitLab License #### 1. Clone the project repository + Clone this project to your local machine. ```bash @@ -75,6 +116,7 @@ cd GitLab-License-Generator ``` #### 2. Run the `make.sh` script + Once all the prerequisites are met, run the script: ```bash @@ -82,6 +124,7 @@ Once all the prerequisites are met, run the script: ``` The script will perform the following actions: + - Download and extract the `gitlab-license` gem. - Copy and modify the required files. - Clone the GitLab source code from GitLab.com. @@ -89,9 +132,11 @@ The script will perform the following actions: - Generate a GitLab license. #### 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. - **If GitLab is installed on your server**: + ```bash sudo cp ./build/public.key /opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub 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: + ```bash docker-compose down docker-compose up -d ``` #### 4. Install the license in GitLab + 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. @@ -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**. If necessary, you can directly access the license upload page via: + ``` /admin/license/new ``` #### 5. Disable Service Ping (optional) + If you want to disable GitLab’s usage data collection (Service Ping), modify GitLab’s configuration file: - Open the configuration file: + ```bash sudo nano /etc/gitlab/gitlab.rb ``` - Add the following line: + ```bash gitlab_rails['usage_ping_enabled'] = false ``` - Reconfigure and restart GitLab: + ```bash sudo gitlab-ctl reconfigure sudo gitlab-ctl restart diff --git a/make.sh b/make.sh index 469aea0..6aa858e 100755 --- a/make.sh +++ b/make.sh @@ -17,7 +17,7 @@ if [ ! -f ".root" ]; then fi WORKING_DIR=$(pwd) -mkdir temp 2> /dev/null || true +mkdir temp 2>/dev/null || true echo "[*] fetching ruby gem version..." RB_GEM_NAME="gitlab-license" @@ -30,14 +30,14 @@ while IFS= read -r line; do RB_GEM_VERSION=${RB_GEM_VERSION%")"} break fi -done <<< "$RB_GEM_LIST_OUTPUT" +done <<<"$RB_GEM_LIST_OUTPUT" echo "[*] gitlab-license version: $RB_GEM_VERSION" RB_GEM_DOWNLOAD_URL="https://rubygems.org/downloads/gitlab-license-$RB_GEM_VERSION.gem" RB_GEM_DOWNLOAD_PATH=$(pwd)/temp/gem/gitlab-license.gem -mkdir -p $(dirname $RB_GEM_DOWNLOAD_PATH) -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 +mkdir -p "$(dirname "$RB_GEM_DOWNLOAD_PATH")" +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 tar -xf gitlab-license.gem tar -xf data.tar.gz @@ -47,31 +47,34 @@ if [ ! -f "./lib/gitlab/license.rb" ]; then fi echo "[*] copying gem..." -rm -rf "$WORKING_DIR/lib" || true +rm -rf "${WORKING_DIR:?}/lib" || true mkdir -p "$WORKING_DIR/lib" -cp -r ./lib/gitlab/* $WORKING_DIR/lib -popd > /dev/null +cp -r ./lib/gitlab/* "$WORKING_DIR/lib" +popd >/dev/null -pushd lib > /dev/null +pushd lib >/dev/null echo "[*] patching lib requirements gem..." # Determine the operating system OS_TYPE="$(uname -s)" -case "$OS_TYPE" in - Linux*) - sed_i_cmd="sed -i";; - Darwin*) - sed_i_cmd="sed -i ''";; - *) - echo "Unsupported OS: $OS_TYPE"; - exit 1;; +case "$OS_TYPE" in +Linux*) + sed_i_cmd="sed -i" + ;; +Darwin*) + sed_i_cmd="sed -i ''" + ;; +*) + echo "Unsupported OS: $OS_TYPE" + exit 1 + ;; esac # 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' {} \; -popd > /dev/null +popd >/dev/null echo "[*] updated gem" @@ -82,22 +85,21 @@ mkdir -p "$GITLAB_SOURCE_CODE_DIR" 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" - BUILD_DIR=$(pwd)/build -mkdir -p $BUILD_DIR +mkdir -p "$BUILD_DIR" echo "[*] scanning features..." FEATURE_LIST_FILE=$BUILD_DIR/features.json -rm -f $FEATURE_LIST_FILE || true +rm -f "${FEATURE_LIST_FILE:?}" || true ./src/scan.features.rb \ - -o $FEATURE_LIST_FILE \ + -o "$FEATURE_LIST_FILE" \ -f "$GITLAB_SOURCE_CODE_DIR/features.rb" echo "[*] generating key pair..." PUBLIC_KEY_FILE=$BUILD_DIR/public.key PRIVATE_KEY_FILE=$BUILD_DIR/private.key -cp -f ./keys/public.key $PUBLIC_KEY_FILE -cp -f ./keys/private.key $PRIVATE_KEY_FILE +cp -f ./keys/public.key "$PUBLIC_KEY_FILE" +cp -f ./keys/private.key "$PRIVATE_KEY_FILE" # execute following command to generate new keys # ./src/generator.keys.rb \ @@ -109,16 +111,16 @@ LICENSE_FILE=$BUILD_DIR/result.gitlab-license LICENSE_JSON_FILE=$BUILD_DIR/license.json ./src/generator.license.rb \ - -f $FEATURE_LIST_FILE \ - --public-key $PUBLIC_KEY_FILE \ - --private-key $PRIVATE_KEY_FILE \ - -o $LICENSE_FILE \ + -f "$FEATURE_LIST_FILE" \ + --public-key "$PUBLIC_KEY_FILE" \ + --private-key "$PRIVATE_KEY_FILE" \ + -o "$LICENSE_FILE" \ --license-name "$LICENSE_NAME" \ --license-company "$LICENSE_COMPANY" \ --license-email "$LICENSE_EMAIL" \ --license-plan "$LICENSE_PLAN" \ --license-user-count "$LICENSE_USER_COUNT" \ --license-expire-year "$LICENSE_EXPIRE_YEAR" \ - --plain-license $LICENSE_JSON_FILE + --plain-license "$LICENSE_JSON_FILE" -echo "[*] done $(basename $0)" +echo "[*] done $(basename "$0")"