2023-05-15 14:38:56 +00:00
name : Deploy
2023-04-21 15:01:40 +00:00
# Define when the workflow should run
on :
# Allow manual triggering of the workflow from the Actions tab
workflow_dispatch :
# Allow inputs to be passed when manually triggering the workflow from the Actions tab
inputs :
DOCKERFILE_PATH :
type : string
2023-05-19 09:02:58 +00:00
description : 'Path to the Dockerfile'
2023-04-21 15:01:40 +00:00
required : true
2023-05-16 11:03:40 +00:00
default : 'dockerfiles/debian_mini'
2023-04-21 15:01:40 +00:00
IMAGE_SIZE :
type : string
2023-05-19 09:02:58 +00:00
description : 'Image size, 950M max'
2023-04-21 15:01:40 +00:00
required : true
2023-05-17 20:47:07 +00:00
default : '600M'
2023-04-21 15:01:40 +00:00
DEPLOY_TO_GITHUB_PAGES :
type : boolean
2023-05-19 09:02:58 +00:00
description : 'Deploy to Github pages'
2023-04-21 15:01:40 +00:00
required : true
default : true
GITHUB_RELEASE :
type : boolean
2023-05-19 09:02:58 +00:00
description : 'Upload GitHub release'
2023-04-21 15:01:40 +00:00
required : true
default : false
jobs :
build :
runs-on : ubuntu-latest # Image to run the worker on.
2023-05-17 15:10:22 +00:00
2023-04-21 15:01:40 +00:00
env :
TAG : "ext2-webvm-base-image" # Tag of docker image.
IMAGE_SIZE : '${{ github.event.inputs.IMAGE_SIZE }}'
DEPLOY_DIR : /webvm_deploy/ # Path to directory where we host the final image from.
2023-05-15 14:38:56 +00:00
2023-04-21 15:01:40 +00:00
permissions : # Permissions to grant the GITHUB_TOKEN.
contents : write # Required permission to make a github release.
actions : 'write' # Required for the Dockerfile path guard clause.
steps :
# Checks-out our repository under $GITHUB_WORKSPACE, so our job can access it
- uses : actions/checkout@v3
# Guard clause that cancels the workflow in case of an invalid DOCKERFILE_PATH.
# The main reason for choosing this workaround for aborting the workflow is the fact that it does not display the workflow as successful, which can set false expectations.
- name : DOCKERFILE_PATH guard clause
shell : bash
run : |
if [ ! -f ${{ github.event.inputs.DOCKERFILE_PATH }} ]; then
echo "::error title=Invalid Dockerfile path::No file found at ${{ github.event.inputs.DOCKERFILE_PATH }}"
gh run cancel ${{ github.run_id }}
gh run watch ${{ github.run_id }}
fi
env :
GH_TOKEN : ${{ github.token }} # As required by the GitHub-CLI
2023-05-17 15:10:22 +00:00
# Setting the IMAGE_NAME variable in GITHUB_ENV to <Dockerfile name>_<date>_<run_id>.ext2.
2023-05-16 15:27:58 +00:00
- name : Generate the image_name.
id : image_name_gen
run : |
2023-05-17 15:10:22 +00:00
echo "IMAGE_NAME=$(basename ${{ github.event.inputs.DOCKERFILE_PATH }})_$(date +%Y%m%d)_${{ github.run_id }}.ext2" >> $GITHUB_ENV
2023-05-16 15:27:58 +00:00
2023-04-21 15:01:40 +00:00
# Create directory to host the image from.
- run : sudo mkdir -p $DEPLOY_DIR
# Build the i386 Dockerfile image.
- run : docker build . --tag $TAG --file ${{ github.event.inputs.DOCKERFILE_PATH }} --platform=i386
# Run the docker image so that we can export the container.
2023-05-15 08:28:02 +00:00
# Run the Docker container with the Google Public DNS nameservers: 8.8.8.8, 8.8.4.4
- run : docker run --dns 8.8.8.8 --dns 8.8.4.4 -d $TAG
2023-04-21 15:01:40 +00:00
# We create and mount the base ext2 image to extract the Docker container's filesystem its contents into.
- name : Create ext2 image.
run : |
# Preallocate space for the ext2 image
2023-05-17 20:01:53 +00:00
sudo fallocate -l $IMAGE_SIZE ${IMAGE_NAME}
2023-04-21 15:01:40 +00:00
# Format to ext2 linux kernel revision 0
2023-05-17 20:01:53 +00:00
sudo mkfs.ext2 -r 0 ${IMAGE_NAME}
2023-04-21 15:01:40 +00:00
# Mount the ext2 image to modify it
2023-05-17 20:01:53 +00:00
sudo mount -o loop -t ext2 ${IMAGE_NAME} /mnt/
2023-05-15 08:28:02 +00:00
# We opt for 'docker cp --archive' over 'docker save' since our focus is solely on the end product rather than individual layers and metadata.
# However, it's important to note that despite being specified in the documentation, the '--archive' flag does not currently preserve uid/gid information when copying files from the container to the host machine.
# Another compelling reason to use 'docker cp' is that it preserves resolv.conf.
2023-04-21 15:01:40 +00:00
- name : Export and unpack container filesystem contents into mounted ext2 image.
run : |
2023-05-15 08:28:02 +00:00
sudo docker cp -a $(sudo docker ps -aq):/ /mnt/
2023-04-21 15:01:40 +00:00
sudo umount /mnt/
# Result is an ext2 image for webvm.
# Move required files for gh-pages deployment to the deployment directory $DEPLOY_DIR.
2023-05-17 07:49:40 +00:00
- run : sudo mv assets examples xterm favicon.ico index.html login.html network.js scrollbar.css serviceWorker.js tower.ico $DEPLOY_DIR
2023-04-21 15:01:40 +00:00
2023-05-17 20:01:53 +00:00
# The .txt suffix enabled HTTP compression for free
- name : Generate image split chunks and .meta file
run : |
sudo split ${{ env.IMAGE_NAME }} ${{ env.DEPLOY_DIR }}/${{ env.IMAGE_NAME }}.c -a 6 -b 128k -x --additional-suffix=.txt
sudo bash -c "stat -c%s ${{ env.IMAGE_NAME }} > ${{ env.DEPLOY_DIR }}/${{ env.IMAGE_NAME }}.meta"
2023-05-08 08:32:54 +00:00
# This step updates the default index.html file by performing the following actions:
2023-04-21 15:01:40 +00:00
# 2. Replaces all occurrences of IMAGE_URL with the URL to the image.
2023-05-08 08:32:54 +00:00
# 3. Replaces all occurrences of DEVICE_TYPE to bytes.
2023-04-21 15:01:40 +00:00
- name : Adjust index.html
run : |
sudo sed -i 's#IMAGE_URL#"${{ env.IMAGE_NAME }}"#g' ${{ env.DEPLOY_DIR }}index.html
2023-05-17 20:01:53 +00:00
sudo sed -i 's#DEVICE_TYPE#"split"#g' ${{ env.DEPLOY_DIR }}index.html
2023-04-21 15:01:40 +00:00
# We generate index.list files for our httpfs to function properly.
- name : make index.list
shell : bash
run : |
find $DEPLOY_DIR -type d | while read -r dir;
do
index_list="$dir/index.list";
sudo rm -f "$index_list";
sudo ls "$dir" | sudo tee "$index_list" > /dev/null;
sudo chmod +rw "$index_list";
sudo echo "created $index_list";
done
# Create a gh-pages artifact in order to deploy to gh-pages.
- name : Upload GitHub Pages artifact
uses : actions/upload-pages-artifact@v1.0.7
with :
# Path of the directory containing the static assets for our gh pages deployment.
path : ${{ env.DEPLOY_DIR }} # optional, default is _site/
- name : github release # To upload our final ext2 image as a github release.
if : ${{ github.event.inputs.GITHUB_RELEASE == 'true' }}
uses : softprops/action-gh-release@v0.1.15
with :
target_commitish : ${{ github.sha }} # Last commit on the GITHUB_REF branch or tag
2023-05-19 09:04:40 +00:00
tag_name : ext2_image
2023-04-21 15:01:40 +00:00
fail_on_unmatched_files : 'true' # Fail in case of no matches with the file(s) glob(s).
files : | # Assets to upload as release.
2023-05-17 20:01:53 +00:00
${{ env.IMAGE_NAME }}
2023-04-21 15:01:40 +00:00
deploy_to_github_pages : # Job that deploys the github-pages artifact to github-pages.
if : ${{ github.event.inputs.DEPLOY_TO_GITHUB_PAGES == 'true' }}
needs : build
environment :
name : github-pages
url : ${{ steps.deployment.outputs.page_url }}
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions :
pages : write # to deploy to Pages
id-token : write # to verify the deployment originates from an appropriate source
runs-on : ubuntu-latest
steps :
# Deployment to github pages
- name : Deploy GitHub Pages site
id : deployment
uses : actions/deploy-pages@v2.0.0