Sync
Sync
This commit is contained in:
commit
7d1e4befe2
5 changed files with 66 additions and 37 deletions
35
.github/workflows/build.yml
vendored
35
.github/workflows/build.yml
vendored
|
@ -11,10 +11,10 @@ on:
|
||||||
- '.github/workflows/**'
|
- '.github/workflows/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
shellcheck:
|
||||||
uses: ./.github/workflows/check.yml
|
uses: ./.github/workflows/check.yml
|
||||||
build:
|
build:
|
||||||
needs: check
|
needs: shellcheck
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
packages: write
|
packages: write
|
||||||
|
@ -23,7 +23,18 @@ jobs:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
-
|
-
|
||||||
name: Build the Docker image
|
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
|
name: Update Minor version
|
||||||
uses: hmanzur/actions-set-secret@v2.0.0
|
uses: hmanzur/actions-set-secret@v2.0.0
|
||||||
|
@ -32,6 +43,14 @@ jobs:
|
||||||
value: $((${{ secrets.MINOR }}+1))
|
value: $((${{ secrets.MINOR }}+1))
|
||||||
repository: ${{ github.repository }}
|
repository: ${{ github.repository }}
|
||||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
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
|
name: Login to Docker Hub
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
|
@ -40,7 +59,9 @@ jobs:
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Push to DockerHub
|
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
|
name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
|
@ -50,7 +71,9 @@ jobs:
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
-
|
-
|
||||||
name: Push to Github Container Registry
|
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:
|
mirror:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
|
@ -64,5 +87,5 @@ jobs:
|
||||||
uses: wangchucheng/git-repo-sync@v0.1.0
|
uses: wangchucheng/git-repo-sync@v0.1.0
|
||||||
with:
|
with:
|
||||||
target-url: ${{ secrets.GITLAB_URL }}
|
target-url: ${{ secrets.GITLAB_URL }}
|
||||||
target-username: ${{ secrets.GITLAB_USERNAME }}
|
|
||||||
target-token: ${{ secrets.GITLAB_TOKEN }}
|
target-token: ${{ secrets.GITLAB_TOKEN }}
|
||||||
|
target-username: ${{ secrets.GITLAB_USERNAME }}
|
||||||
|
|
8
.github/workflows/check.yml
vendored
8
.github/workflows/check.yml
vendored
|
@ -1,14 +1,14 @@
|
||||||
on: [workflow_call]
|
on: [workflow_call]
|
||||||
name: "Shellcheck"
|
name: "Check"
|
||||||
permissions: {}
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
shellcheck:
|
shellcheck:
|
||||||
name: Shellcheck
|
name: shellcheck
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: Run ShellCheck
|
- name: Run ShellCheck
|
||||||
uses: ludeeus/action-shellcheck@master
|
uses: ludeeus/action-shellcheck@master
|
||||||
env:
|
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
|
||||||
|
|
|
@ -27,9 +27,15 @@ ENV DISK_SIZE "16G"
|
||||||
ENV RAM_SIZE "512M"
|
ENV RAM_SIZE "512M"
|
||||||
ENV BOOT "http://www.example.com/image.iso"
|
ENV BOOT "http://www.example.com/image.iso"
|
||||||
|
|
||||||
|
ARG DATE_ARG=""
|
||||||
ARG BUILD_ARG=0
|
ARG BUILD_ARG=0
|
||||||
ARG VERSION_ARG="0.0"
|
ARG VERSION_ARG="0.0"
|
||||||
ENV BUILD=$BUILD_ARG
|
|
||||||
ENV VERSION=$VERSION_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"]
|
ENTRYPOINT ["/run/run.sh"]
|
||||||
|
|
|
@ -29,16 +29,16 @@ configureDHCP() {
|
||||||
echo "docker variable to your container: --device=/dev/vhost-net" && exit 85
|
echo "docker variable to your container: --device=/dev/vhost-net" && exit 85
|
||||||
fi
|
fi
|
||||||
|
|
||||||
VM_NET_TAP="_VmMacvtap"
|
VM_NET_TAP="qemu"
|
||||||
echo "Info: Retrieving IP via DHCP using MAC ${VM_NET_MAC}..."
|
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 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 set "${VM_NET_TAP}" up
|
||||||
|
|
||||||
ip a flush eth0
|
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
|
if [[ "${DHCP_IP}" == [0-9.]* ]]; then
|
||||||
echo "Info: Retrieved IP ${DHCP_IP} via DHCP"
|
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
|
echo "ERROR: Cannot retrieve IP from DHCP using MAC ${VM_NET_MAC}" && exit 16
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ip a flush ${VM_NET_TAP}
|
ip a flush "${VM_NET_TAP}"
|
||||||
|
|
||||||
TAP_PATH="/dev/tap$(</sys/class/net/${VM_NET_TAP}/ifindex)"
|
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)
|
# 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)
|
IFS=: read -r MAJOR MINOR < <(cat /sys/devices/virtual/net/"${VM_NET_TAP}"/tap*/dev)
|
||||||
|
|
||||||
if (( MAJOR < 1)); then
|
if (( MAJOR < 1)); then
|
||||||
echo "ERROR: Cannot find: sys/devices/virtual/net/${VM_NET_TAP}" && exit 18
|
echo "ERROR: Cannot find: sys/devices/virtual/net/${VM_NET_TAP}" && exit 18
|
||||||
fi
|
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 [[ ! -e "${TAP_PATH}" ]]; then
|
||||||
if ! mknod ${TAP_PATH} c $MAJOR $MINOR ; then
|
if ! mknod "${TAP_PATH}" c "$MAJOR" "$MINOR" ; then
|
||||||
echo "ERROR: Cannot mknod: ${TAP_PATH}" && exit 20
|
echo "ERROR: Cannot mknod: ${TAP_PATH}" && exit 20
|
||||||
fi
|
fi
|
||||||
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 -n "ERROR: Please add the following docker variables to your container: "
|
||||||
echo "--device=/dev/vhost-net --device-cgroup-rule='c ${MAJOR}:* rwm'" && exit 21
|
echo "--device=/dev/vhost-net --device-cgroup-rule='c ${MAJOR}:* rwm'" && exit 21
|
||||||
fi
|
fi
|
||||||
|
@ -80,8 +80,8 @@ configureDHCP() {
|
||||||
|
|
||||||
configureNAT () {
|
configureNAT () {
|
||||||
|
|
||||||
|
VM_NET_TAP="qemu"
|
||||||
VM_NET_IP='20.20.20.21'
|
VM_NET_IP='20.20.20.21'
|
||||||
VM_NET_TAP="_VmNatTap"
|
|
||||||
|
|
||||||
#Create bridge with static IP for the VM guest
|
#Create bridge with static IP for the VM guest
|
||||||
brctl addbr dockerbridge
|
brctl addbr dockerbridge
|
||||||
|
@ -113,21 +113,21 @@ configureNAT () {
|
||||||
NET_OPTS="-netdev tap,ifname=${VM_NET_TAP},script=no,downscript=no,id=hostnet0"
|
NET_OPTS="-netdev tap,ifname=${VM_NET_TAP},script=no,downscript=no,id=hostnet0"
|
||||||
|
|
||||||
# Build DNS options from container /etc/resolv.conf
|
# 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')
|
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
|
for nameserver in "${nameservers[@]}"; do
|
||||||
if ! [[ $nameserver =~ .*:.* ]]; then
|
if ! [[ "$nameserver" =~ .*:.* ]]; then
|
||||||
[[ -z $DNS_SERVERS ]] && DNS_SERVERS=$nameserver || DNS_SERVERS="$DNS_SERVERS,$nameserver"
|
[[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="$nameserver" || DNS_SERVERS="$DNS_SERVERS,$nameserver"
|
||||||
fi
|
fi
|
||||||
done
|
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"
|
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"
|
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-search,$searchdomains --dhcp-option=option:domain-name,$domainname"
|
||||||
else
|
else
|
||||||
[[ -z $(hostname -d) ]] || DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-name,$(hostname -d)"
|
[[ -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"
|
[ "$DEBUG" = "Y" ] && echo && echo "$DNSMASQ $DNSMASQ_OPTS"
|
||||||
|
|
||||||
$DNSMASQ $DNSMASQ_OPTS
|
$DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}
|
||||||
}
|
}
|
||||||
|
|
||||||
# ######################################
|
# ######################################
|
||||||
|
|
12
run/run.sh
12
run/run.sh
|
@ -3,12 +3,12 @@ set -eu
|
||||||
|
|
||||||
# Docker environment variabeles
|
# Docker environment variabeles
|
||||||
|
|
||||||
: ${BOOT:=''}. # URL of the ISO file
|
: ${BOOT:=''}. # URL of the ISO file
|
||||||
: ${DEBUG:=''}. # Enable debug mode
|
: ${DEBUG:=''}. # Enable debug mode
|
||||||
: ${ALLOCATE:='Y'} # Preallocate diskspace
|
: ${ALLOCATE:='Y'} # Preallocate diskspace
|
||||||
: ${CPU_CORES:='1'} # vCPU count
|
: ${CPU_CORES:='1'} # Amount of CPU cores
|
||||||
: ${DISK_SIZE:='16G'} # Initial disk size
|
: ${DISK_SIZE:='16G'} # Initial data disk size
|
||||||
: ${RAM_SIZE:='512M'} # Amount of RAM
|
: ${RAM_SIZE:='512M'} # Maximum RAM amount
|
||||||
|
|
||||||
echo "Starting QEMU for Docker v${VERSION}..."
|
echo "Starting QEMU for Docker v${VERSION}..."
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ fi
|
||||||
KVM_OPTS=""
|
KVM_OPTS=""
|
||||||
|
|
||||||
if [ -e /dev/kvm ] && sh -c 'echo -n > /dev/kvm' &> /dev/null; then
|
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"
|
KVM_OPTS=",accel=kvm -enable-kvm -cpu host"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -52,7 +52,7 @@ ARGS="${DEF_OPTS} ${CPU_OPTS} ${RAM_OPTS} ${KVM_OPTS} ${MON_OPTS} ${SERIAL_OPTS}
|
||||||
|
|
||||||
set -m
|
set -m
|
||||||
(
|
(
|
||||||
qemu-system-x86_64 ${ARGS} & echo $! > ${_QEMU_PID}
|
qemu-system-x86_64 ${ARGS:+ $ARGS} & echo $! > "${_QEMU_PID}"
|
||||||
)
|
)
|
||||||
set +m
|
set +m
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue