Skip to content

Commit

Permalink
Show how to use secrets-connected config to create a custom, bootable…
Browse files Browse the repository at this point in the history
…, connectable raspberry pi image directly from Github actions with no manual configuration
  • Loading branch information
aniongithub committed Apr 16, 2021
1 parent 7639424 commit dd71ab6
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI

on:
# Run jobs on push to master or feature branches
push:
branches:
- main
- feature-*

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Checkout submodules
uses: textbook/git-checkout-submodule-action@master

- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
buildx-version: latest
qemu-version: latest

- name: Build
env:
SECRET_IMAGE_NAME: ${{ secrets.IMAGE_NAME }}
SECRET_HOSTNAME: ${{ secrets.HOSTNAME }}
SECRET_FIRST_USER: ${{ secrets.FIRST_USER }}
SECRET_FIRST_USERPASS: ${{ secrets.FIRST_USER_PASS }}
SECRET_SSH_ENABLED: ${{ secrets.SSH_ENABLED }}
SECRET_WPA_SSID: ${{ secrets.WPA_SSID }}
SECRET_WPA_PASSPHRASE: ${{ secrets.WPA_PASSPHRASE }}
SECRET_WPA_COUNTRY: ${{ secrets.WPA_COUNTRY }}
run: |
pushd pi-gen
trap "popd; exit" INT TERM EXIT
./build-docker.sh -c ../config IMAGE_NAME="${SECRET_IMAGE_NAME}" HOSTNAME="${SECRET_HOSTNAME}" FIRST_USER="${SECRET_FIRST_USER}" FIRST_USERPASS="${SECRET_FIRST_USER_PASS}" SSH_ENABLED="${SECRET_SSH_ENABLED}" WPA_SSID="${SECRET_WPA_SSID}" WPA_PASSPHRASE="${SECRET_WPA_PASSPHRASE}" WPA_COUNTRY="${SECRET_WPA_COUNTRY}"
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "pi-gen"]
path = pi-gen
url = https://github.com/aniongithub/pi-gen.git
branch = master
4 changes: 4 additions & 0 deletions bootstrap/00-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
nano
wget
jq
python3-pip
18 changes: 18 additions & 0 deletions bootstrap/01-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash -e

# Install Docker using default installation script
# and perform post-install steps to not require
# sudo for docker commands
echo "Installing docker..."
on_chroot << EOF
curl -sSL get.docker.com | sh
usermod -aG docker ${FIRST_USER_NAME}
EOF

# Install docker-compose
echo "Installing docker-compose..."
on_chroot << EOF
pip3 install docker-compose
# Ensure it's in PATH
ln -sfn /home/${FIRST_USER_NAME}/.local/bin/docker-compose /usr/bin/docker-compose
EOF
8 changes: 8 additions & 0 deletions bootstrap/02-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -e

# Generate wpa_supplicant.conf in /boot so pi will copy it and disable rfkill on startup
echo "Generating wpa_supplicant.conf..."
echo "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev" > ${BOOTFS_DIR}/wpa_supplicant.conf
echo "update_config=1" >> ${BOOTFS_DIR}/wpa_supplicant.conf
echo "country=${WPA_COUNTRY}" >> ${BOOTFS_DIR}/wpa_supplicant.conf
wpa_passphrase ${WPA_SSID} ${WPA_PASSPHRASE} >> ${BOOTFS_DIR}/wpa_supplicant.conf
27 changes: 27 additions & 0 deletions config
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# The directory this config file lives in
CONFIG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd)"

export IMG_NAME=${IMAGE_NAME}
export TARGET_HOSTNAME=${HOSTNAME}

TIMEZONE=$(cat /etc/timezone)
export TIMEZONE_DEFAULT=$TIMEZONE

# TODO: Fix this!
export LOCALE_DEFAULT=${LANG:="en_US.UTF-8"}

export FIRST_USER_NAME=${FIRST_USER}
export FIRST_USER_PASS=${FIRST_USERPASS}

export ENABLE_SSH=${SSH_ENABLED}

# Add additional mounts containing custom steps and files it needs
export ADDL_MOUNTS="${CONFIG_DIR}/bootstrap:/pi-gen/stage2/90-bootstrap:ro ${CONFIG_DIR}/bootstrap-resources:/bootstrap-resources:ro"

# We only want to build a lite image
export STAGE_LIST="stage0 stage1 stage2"

# Set up WiFi
export WPA_ESSID=${WPA_SSID}
export WPA_PASSWORD=${WPA_PASSPHRASE}
export WPA_COUNTRY=${WPA_COUNTRY}
1 change: 1 addition & 0 deletions pi-gen
Submodule pi-gen added at 52fd63

0 comments on commit dd71ab6

Please sign in to comment.