Skip to content

Commit

Permalink
feat: build both agent and inbound-agent images
Browse files Browse the repository at this point in the history
  • Loading branch information
lemeurherve committed Jan 11, 2024
1 parent cfc94cc commit 0ab91ff
Show file tree
Hide file tree
Showing 19 changed files with 557 additions and 384 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/update-dockerhub-description.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update Docker Hub description
- name: Update Docker Hub description for agent
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
enable-url-completion: true
short-description: ${{ github.event.repository.description }}
short-description: This is a base image, which provides the Jenkins agent executable (agent.jar)
repository: jenkins/agent
readme-filepath: ./README_agent.md
- name: Update Docker Hub description for inbound-agent
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
enable-url-completion: true
short-description: This is an image for Jenkins agents using TCP or WebSockets to establish inbound connection to the Jenkins controller
repository: jenkins/inbound-agent
readme-filepath: ./README_inbound-agent.md
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
bats-core/
bats/
target/
build-windows-current.yaml
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pipeline {
}
post {
always {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results.xml')
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results*.xml')
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ export BUILDKIT_PROGRESS=plain
current_arch := $(shell uname -m)
export ARCH ?= $(shell case $(current_arch) in (x86_64) echo "amd64" ;; (i386) echo "386";; (aarch64|arm64) echo "arm64" ;; (armv6*) echo "arm/v6";; (armv7*) echo "arm/v7";; (s390*|riscv*|ppc64le) echo $(current_arch);; (*) echo "UNKNOWN-CPU";; esac)

IMAGE_NAME:=jenkins4eval/agent

# Set to the path of a specific test suite to restrict execution only to this
# default is "all test suites in the "tests/" directory
TEST_SUITES ?= $(CURDIR)/tests

##### Macros
## Check the presence of a CLI in the current PATH
check_cli = type "$(1)" >/dev/null 2>&1 || { echo "Error: command '$(1)' required but not found. Exiting." ; exit 1 ; }
Expand All @@ -42,6 +36,7 @@ build: check-reqs

build-%:
@$(call check_image,$*)
@echo "== building $*"
@set -x; $(bake_base_cli) --set '*.platform=linux/$(ARCH)' '$*'

show:
Expand All @@ -59,7 +54,7 @@ prepare-test: bats check-reqs

## Define bats options based on environment
# common flags for all tests
bats_flags := $(TEST_SUITES)
bats_flags := ""
# if DISABLE_PARALLEL_TESTS true, then disable parallel execution
ifneq (true,$(DISABLE_PARALLEL_TESTS))
# If the GNU 'parallel' command line is absent, then disable parallel execution
Expand All @@ -75,9 +70,10 @@ test-%: prepare-test
@$(call check_image,$*)
# Ensure that the image is built
@make --silent build-$*
# Execute the test harness and write result to a TAP file
@echo "== testing $*"
set -x
IMAGE=$* bats/bin/bats $(bats_flags) | tee target/results-$*.tap
# Each type of image ("agent" or "inbound-agent") has its own tests suite
IMAGE=$* bats/bin/bats $(CURDIR)/tests/tests_$(shell echo $* | cut -d "_" -f 1).bats $(bats_flags) | tee target/results-$*.tap
# convert TAP to JUNIT
docker run --rm -v "$(CURDIR)":/usr/src/app -w /usr/src/app node:16-alpine \
sh -c "npm install tap-xunit -g && cat target/results-$*.tap | tap-xunit --package='jenkinsci.docker.$*' > target/junit-results-$*.xml"
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Jenkins Agent and Inbound Agent Docker images

[![Join the chat at https://gitter.im/jenkinsci/docker](https://badges.gitter.im/jenkinsci/docker.svg)](https://gitter.im/jenkinsci/docker?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![GitHub stars](https://img.shields.io/github/stars/jenkinsci/docker-agent?label=GitHub%20stars)](https://github.com/jenkinsci/docker-agent)
[![GitHub release](https://img.shields.io/github/release/jenkinsci/docker-agent.svg?label=changelog)](https://github.com/jenkinsci/docker-agent/releases/latest)

This repository contains the definition of two images:

## agent
[![Docker Pulls](https://img.shields.io/docker/pulls/jenkins/agent.svg)](https://hub.docker.com/r/jenkins/agent/)

This is a base image for Docker, which includes JDK and the Jenkins agent executable (agent.jar).

See [the `agent` README](./README_agent.md)

## inbound-agent
[![Docker Pulls](https://img.shields.io/docker/pulls/jenkins/inbound-agent.svg)](https://hub.docker.com/r/jenkins/inbound-agent/)

This is an image based on `agent` for [Jenkins](https://jenkins.io) agents using TCP or WebSockets to establish inbound connection to the Jenkins master.

See [the `inbound-agent` README](./README_inbound-agent.md)
29 changes: 26 additions & 3 deletions alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ RUN if [ "$TARGETPLATFORM" != 'linux/arm/v7' ]; then \
cp -r /opt/java/openjdk /javaruntime; \
fi

FROM alpine:"${ALPINE_TAG}" AS build
## Agent image target
FROM alpine:"${ALPINE_TAG}" AS agent

ARG user=jenkins
ARG group=jenkins
ARG uid=1000
ARG gid=1000

RUN addgroup -g "${gid}" "${group}" \
&& adduser -h /home/"${user}" -u "${uid}" -G "${group}" -D "${user}"
&& adduser -h /home/"${user}" -u "${uid}" -G "${group}" -D "${user}" || echo "user ${user} already exists."

ARG AGENT_WORKDIR=/home/"${user}"/agent

Expand Down Expand Up @@ -82,7 +83,7 @@ ENV PATH="${JAVA_HOME}/bin:${PATH}"

USER "${user}"
ENV AGENT_WORKDIR="${AGENT_WORKDIR}"
RUN mkdir /home/"${user}"/.jenkins && mkdir -p "${AGENT_WORKDIR}"
RUN mkdir -p /home/"${user}"/.jenkins && mkdir -p "${AGENT_WORKDIR}"

VOLUME /home/"${user}"/.jenkins
VOLUME "${AGENT_WORKDIR}"
Expand All @@ -96,3 +97,25 @@ LABEL \
org.opencontainers.image.url="https://www.jenkins.io/" \
org.opencontainers.image.source="https://github.com/jenkinsci/docker-agent" \
org.opencontainers.image.licenses="MIT"

## Inbound Agent image target
FROM agent AS inbound-agent

ARG user=jenkins

USER root
COPY ../../jenkins-agent /usr/local/bin/jenkins-agent
RUN chmod +x /usr/local/bin/jenkins-agent &&\
ln -s /usr/local/bin/jenkins-agent /usr/local/bin/jenkins-slave
USER ${user}

LABEL \
org.opencontainers.image.vendor="Jenkins project" \
org.opencontainers.image.title="Official Jenkins Agent Base Docker image" \
org.opencontainers.image.description="This is an image for Jenkins agents using TCP or WebSockets to establish inbound connection to the Jenkins controller" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.url="https://www.jenkins.io/" \
org.opencontainers.image.source="https://github.com/jenkinsci/docker-agent" \
org.opencontainers.image.licenses="MIT"

ENTRYPOINT ["/usr/local/bin/jenkins-agent"]
Loading

0 comments on commit 0ab91ff

Please sign in to comment.