Commit 7d1e4bef authored by Kroese's avatar Kroese Committed by GitHub
Browse files

Sync

Sync
parents 5b6d3d26 8f1a1eda
Loading
Loading
Loading
Loading
+29 −6
Original line number Diff line number Diff line
@@ -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 }}
+4 −4
Original line number Diff line number Diff line
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
        SHELLCHECK_OPTS: -x -e SC2002 -e SC2223 -e SC2034 -e SC2064 
+7 −1
Original line number Diff line number Diff line
@@ -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"]
+20 −20
Original line number Diff line number Diff line
@@ -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$(</sys/class/net/${VM_NET_TAP}/ifindex)"

  # create dev file (there is no udev in container: need to be done manually)
  IFS=: read MAJOR MINOR < <(cat /sys/devices/virtual/net/${VM_NET_TAP}/tap*/dev)
  # Create dev file (there is no udev in container: need to be done manually)
  IFS=: read -r MAJOR MINOR < <(cat /sys/devices/virtual/net/"${VM_NET_TAP}"/tap*/dev)

  if (( MAJOR < 1)); then
     echo "ERROR: Cannot find: sys/devices/virtual/net/${VM_NET_TAP}" && exit 18
  fi

  [[ ! -e ${TAP_PATH} ]] && [[ -e /dev0/${TAP_PATH##*/} ]] && ln -s /dev0/${TAP_PATH##*/} ${TAP_PATH}
  [[ ! -e "${TAP_PATH}" ]] && [[ -e "/dev0/${TAP_PATH##*/}" ]] && ln -s "/dev0/${TAP_PATH##*/}" "${TAP_PATH}"

  if [[ ! -e ${TAP_PATH} ]]; then
    if ! mknod ${TAP_PATH} c $MAJOR $MINOR ; then
  if [[ ! -e "${TAP_PATH}" ]]; then
    if ! mknod "${TAP_PATH}" c "$MAJOR" "$MINOR" ; then
      echo "ERROR: Cannot mknod: ${TAP_PATH}" && exit 20
    fi
  fi

  if ! exec 30>>$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} 
}

# ######################################
+6 −6
Original line number Diff line number Diff line
@@ -6,9 +6,9 @@ set -eu
: ${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