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 }} 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 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"] diff --git a/run/network.sh b/run/network.sh index c8a7fc9..b218e6d 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,26 @@ configureDHCP() { echo "ERROR: Cannot retrieve IP from DHCP using MAC ${VM_NET_MAC}" && exit 16 fi - ip a flush ${VM_NET_TAP} + 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 @@ -80,8 +80,8 @@ configureDHCP() { configureNAT () { + VM_NET_TAP="qemu" VM_NET_IP='20.20.20.21' - VM_NET_TAP="_VmNatTap" #Create bridge with static IP for the VM guest brctl addbr dockerbridge @@ -113,21 +113,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 +135,7 @@ configureNAT () { [ "$DEBUG" = "Y" ] && echo && echo "$DNSMASQ $DNSMASQ_OPTS" - $DNSMASQ $DNSMASQ_OPTS + $DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} } # ###################################### 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