From ec6e9ad98a3369d2460c19682e0a91f5d0336c4f Mon Sep 17 00:00:00 2001 From: apporc Date: Thu, 23 Feb 2023 20:48:30 +0800 Subject: [PATCH] add jenkins slave --- .github/workflows/jenkins-slave.yml | 39 +++++++++++++++++++++++ jenkins-slave/010_jenkins-nopasswd | 1 + jenkins-slave/Dockerfile | 48 +++++++++++++++++++++++++++++ jenkins-slave/README.md | 1 + 4 files changed, 89 insertions(+) create mode 100644 .github/workflows/jenkins-slave.yml create mode 100644 jenkins-slave/010_jenkins-nopasswd create mode 100644 jenkins-slave/Dockerfile create mode 100644 jenkins-slave/README.md diff --git a/.github/workflows/jenkins-slave.yml b/.github/workflows/jenkins-slave.yml new file mode 100644 index 0000000..f0dd44b --- /dev/null +++ b/.github/workflows/jenkins-slave.yml @@ -0,0 +1,39 @@ +name: Jenkins slave Docker Image Build + +on: + workflow_dispatch: + inputs: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: greymass/jenkins-slave + +jobs: + docker: + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@v2 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: latest + + - name: Log in to the Container registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: ./jenkins-slave/ + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} diff --git a/jenkins-slave/010_jenkins-nopasswd b/jenkins-slave/010_jenkins-nopasswd new file mode 100644 index 0000000..c9f5c2a --- /dev/null +++ b/jenkins-slave/010_jenkins-nopasswd @@ -0,0 +1 @@ +jenkins ALL=(ALL) NOPASSWD: ALL diff --git a/jenkins-slave/Dockerfile b/jenkins-slave/Dockerfile new file mode 100644 index 0000000..82f6759 --- /dev/null +++ b/jenkins-slave/Dockerfile @@ -0,0 +1,48 @@ +FROM jenkins/inbound-agent + +USER root +RUN apt-get update \ + && apt-get upgrade -y \ + && apt-get install -y --no-install-recommends \ + locales \ + sudo \ + vim \ + curl \ + telnet \ + git \ + tmux \ + gcc \ + gnupg \ + python3 \ + python3-pip \ + python3-wheel \ + ansible \ + tox \ + ca-certificates \ + apt-transport-https \ + software-properties-common \ + && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 \ + && curl -sSL https://download.docker.com/linux/debian/gpg -o /tmp/docker.gpg \ + && apt-key add /tmp/docker.gpg \ + && rm /tmp/docker.gpg \ + && add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" \ + && curl -sSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key -o /tmp/node.gpg \ + && apt-key add /tmp/node.gpg \ + && rm /tmp/node.gpg \ + && echo "deb https://deb.nodesource.com/node_16.x $(lsb_release -cs) main" > /etc/apt/sources.list.d/nodesource.list \ + && echo "deb-src https://deb.nodesource.com/node_16.x $(lsb_release -cs) main" >> /etc/apt/sources.list.d/nodesource.list \ + && apt-get update \ + && apt-cache policy docker-ce \ + && apt-get install -y --no-install-recommends docker-ce nodejs \ + && update-alternatives --remove python /usr/bin/python2 \ + && update-alternatives --install /usr/bin/python python /usr/bin/python3 10 \ + && update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 10 \ + && rm -rf /var/lib/apt/lists/* + +RUN usermod -aG docker jenkins + +RUN pip install --no-cache-dir pbr devpi-client + +COPY 010_jenkins-nopasswd /etc/sudoers.d/ + +USER jenkins diff --git a/jenkins-slave/README.md b/jenkins-slave/README.md new file mode 100644 index 0000000..51f8da0 --- /dev/null +++ b/jenkins-slave/README.md @@ -0,0 +1 @@ +customized jenkins slave container