From 4937a98b32a8837d173f411d7d80eb0329abea6b Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 21 Apr 2023 12:39:00 +0200 Subject: [PATCH 1/6] Sync --- run/network.sh | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/run/network.sh b/run/network.sh index c8a7fc9..05aa151 100644 --- a/run/network.sh +++ b/run/network.sh @@ -29,16 +29,16 @@ configureDHCP() { echo "docker variable to your container: --device=/dev/vhost-net" && exit 85 fi - VM_NET_TAP="_VmMacvtap" + VM_NET_TAP="qemu" echo "Info: Retrieving IP via DHCP using MAC ${VM_NET_MAC}..." - ip l add link eth0 name ${VM_NET_TAP} address ${VM_NET_MAC} type macvtap mode bridge || true - ip l set ${VM_NET_TAP} up + ip l add link eth0 name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge || true + ip l set "${VM_NET_TAP}" up ip a flush eth0 - ip a flush ${VM_NET_TAP} + ip a flush "${VM_NET_TAP}" - DHCP_IP=$( dhclient -v ${VM_NET_TAP} 2>&1 | grep ^bound | cut -d' ' -f3 ) + DHCP_IP=$( dhclient -v "${VM_NET_TAP}" 2>&1 | grep ^bound | cut -d' ' -f3 ) if [[ "${DHCP_IP}" == [0-9.]* ]]; then echo "Info: Retrieved IP ${DHCP_IP} via DHCP" @@ -46,26 +46,29 @@ configureDHCP() { echo "ERROR: Cannot retrieve IP from DHCP using MAC ${VM_NET_MAC}" && exit 16 fi - ip a flush ${VM_NET_TAP} + # Store IP for Docker healthcheck + echo "${DHCP_IP}" > "/var/qemu.ip" + + ip a flush "${VM_NET_TAP}" TAP_PATH="/dev/tap$(>$TAP_PATH; then + if ! exec 30>>"$TAP_PATH"; then echo -n "ERROR: Please add the following docker variables to your container: " echo "--device=/dev/vhost-net --device-cgroup-rule='c ${MAJOR}:* rwm'" && exit 21 fi @@ -83,6 +86,9 @@ configureNAT () { VM_NET_IP='20.20.20.21' VM_NET_TAP="_VmNatTap" + # Store IP for Docker healthcheck + echo "${VM_NET_IP}" > "/var/qemu.ip" + #Create bridge with static IP for the VM guest brctl addbr dockerbridge ip addr add ${VM_NET_IP%.*}.1/24 broadcast ${VM_NET_IP%.*}.255 dev dockerbridge @@ -113,21 +119,21 @@ configureNAT () { NET_OPTS="-netdev tap,ifname=${VM_NET_TAP},script=no,downscript=no,id=hostnet0" # Build DNS options from container /etc/resolv.conf - nameservers=($(grep '^nameserver' /etc/resolv.conf | sed 's/nameserver //')) + mapfile -t nameservers < <(grep '^nameserver' /etc/resolv.conf | sed 's/nameserver //') searchdomains=$(grep '^search' /etc/resolv.conf | sed 's/search //' | sed 's/ /,/g') - domainname=$(echo $searchdomains | awk -F"," '{print $1}') + domainname=$(echo "$searchdomains" | awk -F"," '{print $1}') for nameserver in "${nameservers[@]}"; do - if ! [[ $nameserver =~ .*:.* ]]; then - [[ -z $DNS_SERVERS ]] && DNS_SERVERS=$nameserver || DNS_SERVERS="$DNS_SERVERS,$nameserver" + if ! [[ "$nameserver" =~ .*:.* ]]; then + [[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="$nameserver" || DNS_SERVERS="$DNS_SERVERS,$nameserver" fi done - [[ -z $DNS_SERVERS ]] && DNS_SERVERS="1.1.1.1" + [[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="1.1.1.1" DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:dns-server,$DNS_SERVERS --dhcp-option=option:router,${VM_NET_IP%.*}.1" - if [ -n "$searchdomains" -a "$searchdomains" != "." ]; then + if [ -n "$searchdomains" ] && [ "$searchdomains" != "." ]; then DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-search,$searchdomains --dhcp-option=option:domain-name,$domainname" else [[ -z $(hostname -d) ]] || DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-name,$(hostname -d)" @@ -135,7 +141,7 @@ configureNAT () { [ "$DEBUG" = "Y" ] && echo && echo "$DNSMASQ $DNSMASQ_OPTS" - $DNSMASQ $DNSMASQ_OPTS + $DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} } # ###################################### From c39f22e7c142b99b12fa981a48d3f2dffb91b65e Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 21 Apr 2023 12:42:00 +0200 Subject: [PATCH 2/6] Sync --- run/network.sh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/run/network.sh b/run/network.sh index 05aa151..b218e6d 100644 --- a/run/network.sh +++ b/run/network.sh @@ -46,9 +46,6 @@ configureDHCP() { echo "ERROR: Cannot retrieve IP from DHCP using MAC ${VM_NET_MAC}" && exit 16 fi - # Store IP for Docker healthcheck - echo "${DHCP_IP}" > "/var/qemu.ip" - ip a flush "${VM_NET_TAP}" TAP_PATH="/dev/tap$( "/var/qemu.ip" #Create bridge with static IP for the VM guest brctl addbr dockerbridge From 5de55ee04a44b2fa169fabb7b303e0401a1aca6b Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 21 Apr 2023 12:46:06 +0200 Subject: [PATCH 3/6] Sync --- run/run.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/run/run.sh b/run/run.sh index 6b950ce..f0231c4 100755 --- a/run/run.sh +++ b/run/run.sh @@ -3,12 +3,12 @@ set -eu # Docker environment variabeles -: ${BOOT:=''}. # URL of the ISO file +: ${BOOT:=''}. # URL of the ISO file : ${DEBUG:=''}. # Enable debug mode : ${ALLOCATE:='Y'} # Preallocate diskspace -: ${CPU_CORES:='1'} # vCPU count -: ${DISK_SIZE:='16G'} # Initial disk size -: ${RAM_SIZE:='512M'} # Amount of RAM +: ${CPU_CORES:='1'} # Amount of CPU cores +: ${DISK_SIZE:='16G'} # Initial data disk size +: ${RAM_SIZE:='512M'} # Maximum RAM amount echo "Starting QEMU for Docker v${VERSION}..." @@ -32,7 +32,7 @@ fi KVM_OPTS="" if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then - if [[ $(grep -e vmx -e svm /proc/cpuinfo) ]]; then + if grep -q -e vmx -e svm /proc/cpuinfo; then KVM_OPTS=",accel=kvm -enable-kvm -cpu host" fi fi @@ -52,7 +52,7 @@ ARGS="${DEF_OPTS} ${CPU_OPTS} ${RAM_OPTS} ${KVM_OPTS} ${MON_OPTS} ${SERIAL_OPTS} set -m ( - qemu-system-x86_64 ${ARGS} & echo $! > ${_QEMU_PID} + qemu-system-x86_64 ${ARGS:+ $ARGS} & echo $! > "${_QEMU_PID}" ) set +m From 7ff3297440cd49e4fb5f77f410cbf37b916358ce Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 21 Apr 2023 12:48:33 +0200 Subject: [PATCH 4/6] Sync --- Dockerfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7677ff5..c98f35f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,9 +27,15 @@ ENV DISK_SIZE "16G" ENV RAM_SIZE "512M" ENV BOOT "http://www.example.com/image.iso" +ARG DATE_ARG="" ARG BUILD_ARG=0 ARG VERSION_ARG="0.0" -ENV BUILD=$BUILD_ARG ENV VERSION=$VERSION_ARG +LABEL org.opencontainers.image.created=${DATE_ARG} +LABEL org.opencontainers.image.revision=${BUILD_ARG} +LABEL org.opencontainers.image.version=${VERSION_ARG} +LABEL org.opencontainers.image.url=https://hub.docker.com/r/kroese/docker-qemu/ +LABEL org.opencontainers.image.source=https://github.com/kroese/docker-qemu/ + ENTRYPOINT ["/run/run.sh"] From 232e0eed8e987ce0bb01c3362fdfc65ac2ca97ed Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 21 Apr 2023 12:52:04 +0200 Subject: [PATCH 5/6] Update build.yml --- .github/workflows/build.yml | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fef736a..8de1e84 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,10 +11,10 @@ on: - '.github/workflows/**' jobs: - check: + shellcheck: uses: ./.github/workflows/check.yml build: - needs: check + needs: shellcheck runs-on: ubuntu-latest permissions: packages: write @@ -23,7 +23,18 @@ jobs: - uses: actions/checkout@v3 - name: Build the Docker image - run: docker build . --file Dockerfile --build-arg "VERSION_ARG=${{ secrets.MAJOR }}.${{ secrets.MINOR }}" --build-arg "BUILD_ARG=${GITHUB_RUN_ID}" --label "id=${GITHUB_RUN_ID}" --label "version=${{ secrets.MAJOR }}.${{ secrets.MINOR }}" --tag "${{ github.repository }}:latest" --tag "${{ github.repository }}:${{ secrets.MAJOR }}.${{ secrets.MINOR }}" --tag "ghcr.io/${{ github.repository }}:latest" --tag "ghcr.io/${{ github.repository }}:${{ secrets.MAJOR }}.${{ secrets.MINOR }}" + run: | + docker build . \ + --file Dockerfile \ + --build-arg "VERSION_ARG=${{ secrets.MAJOR }}.${{ secrets.MINOR }}" \ + --build-arg "BUILD_ARG=${GITHUB_RUN_ID}" \ + --build-arg "DATE_ARG=${{ github.event.repository.updated_at }}" \ + --label "build=${GITHUB_RUN_ID}" \ + --label "version=${{ secrets.MAJOR }}.${{ secrets.MINOR }}" \ + --tag "${{ github.repository }}:latest" \ + --tag "${{ github.repository }}:${{ secrets.MAJOR }}.${{ secrets.MINOR }}" \ + --tag "ghcr.io/${{ github.repository }}:latest" \ + --tag "ghcr.io/${{ github.repository }}:${{ secrets.MAJOR }}.${{ secrets.MINOR }}" - name: Update Minor version uses: hmanzur/actions-set-secret@v2.0.0 @@ -32,6 +43,14 @@ jobs: value: $((${{ secrets.MINOR }}+1)) repository: ${{ github.repository }} token: ${{ secrets.REPO_ACCESS_TOKEN }} + - + name: Create tag + uses: rickstaa/action-create-tag@v1 + id: "tag_create" + with: + tag: "v${{ secrets.MAJOR }}.${{ secrets.MINOR }}" + tag_exists_error: false + message: "Release v${{ secrets.MAJOR }}.${{ secrets.MINOR }}" - name: Login to Docker Hub uses: docker/login-action@v2 @@ -40,7 +59,9 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Push to DockerHub - run: docker push "${{ github.repository }}:${{ secrets.MAJOR }}.${{ secrets.MINOR }}" && docker push "${{ github.repository }}:latest" + run: | + docker push "${{ github.repository }}:${{ secrets.MAJOR }}.${{ secrets.MINOR }}" &&\ + docker push "${{ github.repository }}:latest" - name: Login to GitHub Container Registry uses: docker/login-action@v2 @@ -50,7 +71,9 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Push to Github Container Registry - run: docker push "ghcr.io/${{ github.repository }}:${{ secrets.MAJOR }}.${{ secrets.MINOR }}" && docker push "ghcr.io/${{ github.repository }}:latest" + run: | + docker push "ghcr.io/${{ github.repository }}:${{ secrets.MAJOR }}.${{ secrets.MINOR }}" && \ + docker push "ghcr.io/${{ github.repository }}:latest" mirror: runs-on: ubuntu-latest permissions: @@ -64,5 +87,5 @@ jobs: uses: wangchucheng/git-repo-sync@v0.1.0 with: target-url: ${{ secrets.GITLAB_URL }} - target-username: ${{ secrets.GITLAB_USERNAME }} target-token: ${{ secrets.GITLAB_TOKEN }} + target-username: ${{ secrets.GITLAB_USERNAME }} From 8f1a1edaa6392ae47b0bd946fd7c8c32955eb7bc Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 21 Apr 2023 12:53:23 +0200 Subject: [PATCH 6/6] Update check.yml --- .github/workflows/check.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 7f69165..40bfce0 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,14 +1,14 @@ on: [workflow_call] -name: "Shellcheck" +name: "Check" permissions: {} jobs: shellcheck: - name: Shellcheck + name: shellcheck runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Run ShellCheck uses: ludeeus/action-shellcheck@master - env: - SHELLCHECK_OPTS: -e SC2001 -e SC2002 -e SC2116 -e SC2034 -e SC1091 -e SC2143 -e SC2223 -e SC2086 -e SC2145 -e SC2015 -e SC2268 -e SC2207 -e SC2064 -e SC2162 -e SC2153 -e SC2166 +env: + SHELLCHECK_OPTS: -x -e SC2002 -e SC2223 -e SC2034 -e SC2064