Skip to content

Commit

Permalink
Merge remote-tracking branch 'vnoi/master' into patches
Browse files Browse the repository at this point in the history
  • Loading branch information
minhnhatnoe committed Jan 20, 2024
2 parents d2c7db5 + 18f0db5 commit 53f3bc7
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 37 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/push-self-hosted.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build ISO Image (self-hosted)

# Avoids having multiple instances running
concurrency:
group: build-iso
cancel-in-progress: true

on:
push:
tags:
- "v*"
workflow_dispatch:

env:
image_name: "VNOI Ubuntu ${{ github.ref }}"

jobs:
build:
name: Build and push image
runs-on: self-hosted

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Write authorized_keys
run: echo $CONTENT | base64 -d > $FILENAME
env:
CONTENT: ${{ secrets.AUTHORIZED_KEYS }}
FILENAME: src/misc/authorized_keys

- name: Write config.local.sh
run: echo $CONTENT | base64 -d > $FILENAME
env:
CONTENT: ${{ secrets.CONFIG_LOCAL_SH }}
FILENAME: config.local.sh

- name: Write src/config.local.sh
run: echo $CONTENT | base64 -d > $FILENAME
env:
CONTENT: ${{ secrets.SRC_CONFIG_LOCAL_SH }}
FILENAME: src/config.local.sh

- name: Write src/config.sh
run: echo $CONTENT | base64 -d > $FILENAME
env:
CONTENT: ${{ secrets.SRC_CONFIG_SH }}
FILENAME: src/config.sh

- name: Build image
run: sudo ./build.sh icpc_build --github-actions

# ----------------------- #
# Push to Github Releases #
# ----------------------- #
- name: Create Release
uses: actions/create-release@v1
if: ${{ github.event.inputs.generate_iso == 'release' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ env.image_name }}
draft: false
prerelease: false
53 changes: 42 additions & 11 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish ISO Image
name: Build ISO Image

# Avoids having multiple instances running
concurrency:
Expand All @@ -9,6 +9,15 @@ on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
generate_iso:
description: 'Choose generated ISO file storage location'
required: false
type: choice
options:
- 'server'
- 'release'

env:
image_name: "VNOI Ubuntu ${{ github.ref }}"
Expand All @@ -26,31 +35,35 @@ jobs:
run: echo $CONTENT | base64 -d > $FILENAME
env:
CONTENT: ${{ secrets.AUTHORIZED_KEYS }}
FILENAME: authorized_keys
FILENAME: src/misc/authorized_keys

- name: Write local_config.sh
- name: Write config.local.sh
run: echo $CONTENT | base64 -d > $FILENAME
env:
CONTENT: ${{ secrets.LOCAL_CONFIG }}
FILENAME: local_config.sh
CONTENT: ${{ secrets.CONFIG_LOCAL_SH }}
FILENAME: config.local.sh

- name: Write config.local.sh
- name: Write src/config.local.sh
run: echo $CONTENT | base64 -d > $FILENAME
env:
CONTENT: ${{ secrets.CONFIG_LOCAL_SH }}
CONTENT: ${{ secrets.SRC_CONFIG_LOCAL_SH }}
FILENAME: src/config.local.sh

- name: Write config.sh
- name: Write src/config.sh
run: echo $CONTENT | base64 -d > $FILENAME
env:
CONTENT: ${{ secrets.CONFIG_SH }}
CONTENT: ${{ secrets.SRC_CONFIG_SH }}
FILENAME: src/config.sh

- name: Build image
run: sudo ./build.sh icpc_build
run: sudo ./build.sh icpc_build --github-actions

# ----------------------- #
# Push to Github Releases #
# ----------------------- #
- name: Create Release
uses: actions/create-release@v1
if: ${{ github.event.inputs.generate_iso == 'release' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand All @@ -60,9 +73,27 @@ jobs:
prerelease: false

- name: Split ISO
run: mkdir iso-parts; split -b 2000MB live-build/contestant.iso iso-parts/contestant
if: ${{ github.event.inputs.generate_iso == 'release' }}
run: then mkdir iso-parts; split -b 2000MB live-build/contestant.iso iso-parts/contestant

- name: Upload ISO
if: ${{ github.event.inputs.generate_iso == 'release' }}
uses: softprops/action-gh-release@v1
with:
files: iso-parts/contestant*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# ----------------------- #
# Push to Server #
# ----------------------- #
- name: Push to Server
if: ${{ github.event.inputs.generate_iso == 'server' }}
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.SCP_HOST }}
username: ${{ secrets.SCP_USERNAME }}
key: ${{ secrets.SCP_KEY }}
port: 22
source: live-build/contestant.iso
target: ${{ secrets.SCP_TARGET }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local_config.sh
config.local.sh
live-build/
*.iso
authorized_keys
55 changes: 51 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,56 @@
# image-builder
This repo contains script to build a `.iso` file to install customized Ubuntu.
This repo contains script to build a `.iso` file to install customized Ubuntu for ICPC contests.

# Usage
Firstly, make a copy of `config.sh` called `local_config.sh` and change its content. You will want to change the `MIRROR` for faster installation.

Then, run `./build.sh build` as `root`.
## Prerequisites

Install the `.iso` file on required machines, then head to `src/` for more information.
> Note: The builder will require root access and may bind, use, and alternate two folders `/dev/` and `/run/`. If an error occurs during the run and the builder is not able to unmount the folders, it will be necessary to perform a physical hard reboot. Therefore, **it is recommended to run the builder in a virtual machine**.
The builder requires a Linux system with at least 80GB of free storage and 4GB of RAM. The builder is tested on Ubuntu 20.04 LTS and 22.04 LTS.

In case you want to build on a virtual machine, it is recommended to use VirtualBox, with **FIXED SIZE STORAGE** of at least 80GB and **4GB of RAM**.

First, pull the repository and enter the directory:

```bash
git clone https://github.com/VNOI-Admin/image-builder.git
cd image-builder
```

## Configuration

After cloning the repository, you need to configure the builder. There are several files that need to be configured before building the image:

- `config.local.sh`: A local copy of `config.sh` with personal configuration. This contains two important configuration variables:
- `ICPC_URL`: The URL to the ICPC ISO file. The ICPC Global may release new version of the ISO file that may overwrite the old one. Therefore, if errors related to failed download occur, please update this variable.
- `SUPER_PASSWD`: The password for the `root` user and bootloader.
- `src/config.sh`: This a local copy of `src/config.sh` with machine-wide configuration. This contains several important configuration variables:
- `WEBSERVER_PUBLIC_ADDRESS`: The public address of the webserver, commonly for the backup server. This is accessible by the contestants without the need of VPN, therefore should only be used in case of VPN failure.
- `AUTH_ADDRESS`: The public address of the authentication and VPN central server.
- `SUBNET`: The subnet of the service nodes on the VPN network.
- `src/config.local.sh`: This is an optional configuration file of `src/config.local.sh`. By setting the `VERSION` variable, it will store the version of the build to the image. Useful for debugging and tracking the version of the image.

## Building

To build the image for ICPC contests, run the following command:

```bash
sudo ./build.sh icpc_build
```

In case you want to use a specific version of the original ICPC ISO file, you can put the file inside the folder and rename it to `icpc-image.iso`. The builder will automatically use the file instead of downloading from the ICPC Global website.

In case you want to forcefully download the original ICPC ISO file, you can run the following command:

```bash
sudo ./build.sh icpc_build --force
```

In case you want to optimize the build process, you can run the following command:

```bash
sudo ./build.sh icpc_build --github-action
```

This will automatically remove files that are not needed in the final stage of the build process. Should only be used in CI/CD environment or building on systems with limited storage, not for development.
Loading

0 comments on commit 53f3bc7

Please sign in to comment.