Skip to content

Commit 8f142fb

Browse files
committed
feat: optimize Docker setup for E2E testing with dynamic base image support
1 parent 68032fa commit 8f142fb

5 files changed

Lines changed: 68 additions & 32 deletions

File tree

.semaphore/semaphore.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ agent:
55
type: f1-standard-2
66
os_image: ubuntu2404
77

8+
global_job_config:
9+
secrets:
10+
- name: semreg-semaphoredev-credentials
11+
prologue:
12+
commands:
13+
- echo $SEMAPHORE_REGISTRY_PASSWORD | docker login --username "$SEMAPHORE_REGISTRY_USERNAME" --password-stdin $SEMAPHORE_REGISTRY_HOST || echo "Semaphore Registry login failed, but continuing the build process." && true
14+
- export REGISTRY_HOST=$SEMAPHORE_REGISTRY_HOST
15+
- export E2E_BASE_IMAGE="$SEMAPHORE_REGISTRY_HOST/agent-e2e-base"
16+
817
execution_time_limit:
918
minutes: 10
1019

@@ -80,8 +89,20 @@ blocks:
8089
commands:
8190
- test-results publish junit-report.xml
8291

83-
- name: "Docker Executor E2E"
92+
- name: "E2E Base Image"
8493
dependencies: []
94+
task:
95+
prologue:
96+
commands:
97+
- checkout
98+
jobs:
99+
- name: Build and push
100+
commands:
101+
- docker build -f Dockerfile.test.base -t "$E2E_BASE_IMAGE" .
102+
- docker push "$E2E_BASE_IMAGE"
103+
104+
- name: "Docker Executor E2E"
105+
dependencies: ["E2E Base Image"]
85106
task:
86107
secrets:
87108
- name: aws-ecr-agent-e2e-secret
@@ -98,6 +119,7 @@ blocks:
98119
commands:
99120
- sem-version go 1.24.11
100121
- checkout
122+
- docker pull "$E2E_BASE_IMAGE"
101123
- go version
102124
- go get
103125
- go build
@@ -155,7 +177,7 @@ blocks:
155177
- compose_v1
156178

157179
- name: "Hosted E2E tests"
158-
dependencies: []
180+
dependencies: ["E2E Base Image"]
159181
task:
160182
env_vars:
161183
- name: GO111MODULE
@@ -165,6 +187,7 @@ blocks:
165187
commands:
166188
- sem-version go 1.24.11
167189
- checkout
190+
- docker pull "$E2E_BASE_IMAGE"
168191
- go version
169192
- go get
170193
- go build
@@ -190,7 +213,7 @@ blocks:
190213
- job_logs_as_artifact_trimmed
191214

192215
- name: "Self hosted E2E"
193-
dependencies: []
216+
dependencies: ["E2E Base Image"]
194217
task:
195218
env_vars:
196219
- name: GO111MODULE
@@ -202,6 +225,7 @@ blocks:
202225
commands:
203226
- sem-version go 1.24.11
204227
- checkout
228+
- docker pull "$E2E_BASE_IMAGE"
205229
- go version
206230
- go get
207231
- go build
@@ -225,7 +249,7 @@ blocks:
225249
- docker_compose_fail_on_missing_host_files
226250

227251
- name: "Kubernetes Executor E2E"
228-
dependencies: []
252+
dependencies: ["E2E Base Image"]
229253
task:
230254
secrets:
231255
- name: aws-ecr-agent-e2e-secret
@@ -246,6 +270,7 @@ blocks:
246270
- /tmp/minikube-linux-amd64 config set WantUpdateNotification false
247271
- /tmp/minikube-linux-amd64 start --driver=docker
248272
- checkout
273+
- docker pull "$E2E_BASE_IMAGE"
249274
- mkdir /tmp/agent
250275
# The docker container uses root, and not semaphore
251276
- grep -rl "/home/semaphore" ~/.kube | xargs sed -i 's/home\/semaphore/root/g'

Dockerfile.test

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
1-
FROM python:3
2-
3-
RUN apt-get update && \
4-
apt-get install curl -y && \
5-
curl -sSL https://get.docker.com/ | sh && \
6-
apt-get install -y ssh docker-compose-plugin && \
7-
# Install standalone docker-compose for backward compatibility
8-
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && \
9-
chmod +x /usr/local/bin/docker-compose && \
10-
# pin pyyaml to 5.3.1 until https://github.com/yaml/pyyaml/issues/724 is fixed
11-
pip install pyyaml==5.3.1 && \
12-
pip install awscli
13-
14-
# By default, sshd runs on port 22, we need it to run on port 2222
15-
RUN sed -i 's/#Port 22/Port 2222/g' /etc/ssh/sshd_config
16-
17-
# kubectl is required to be present in the container running the agent
18-
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
19-
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
20-
21-
# Semaphore toolbox should also be available
22-
RUN curl -sL https://github.com/semaphoreci/toolbox/releases/latest/download/self-hosted-linux.tar -o toolbox.tar && \
23-
tar -xf toolbox.tar && \
24-
mv toolbox /root/.toolbox && \
25-
/root/.toolbox/install-toolbox && \
26-
echo 'source ~/.toolbox/toolbox' >> /root/.bash_profile && \
27-
rm toolbox.tar
1+
ARG BASE_IMAGE=python:3
2+
FROM ${BASE_IMAGE}
283

294
ADD server.key /app/server.key
305
ADD server.crt /app/server.crt

Dockerfile.test.base

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM python:3
2+
3+
RUN apt-get update && \
4+
apt-get install curl -y && \
5+
curl -sSL https://get.docker.com/ | sh && \
6+
apt-get install -y ssh docker-compose-plugin && \
7+
# Install standalone docker-compose for backward compatibility
8+
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && \
9+
chmod +x /usr/local/bin/docker-compose && \
10+
# pin pyyaml to 5.3.1 until https://github.com/yaml/pyyaml/issues/724 is fixed
11+
pip install pyyaml==5.3.1 && \
12+
pip install awscli
13+
14+
# By default, sshd runs on port 22, we need it to run on port 2222
15+
RUN sed -i 's/#Port 22/Port 2222/g' /etc/ssh/sshd_config
16+
17+
# kubectl is required to be present in the container running the agent
18+
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
19+
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
20+
21+
# Semaphore toolbox should also be available
22+
RUN curl -sL https://github.com/semaphoreci/toolbox/releases/latest/download/self-hosted-linux.tar -o toolbox.tar && \
23+
tar -xf toolbox.tar && \
24+
mv toolbox /root/.toolbox && \
25+
/root/.toolbox/install-toolbox && \
26+
echo 'source ~/.toolbox/toolbox' >> /root/.bash_profile && \
27+
rm toolbox.tar
28+
29+
WORKDIR /app

test/e2e_support/api_mode.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ class ApiMode
1010
def boot_up_agent
1111
system "docker stop $(docker ps -q)"
1212
system "docker rm $(docker ps -qa)"
13-
system "docker build -t agent -f Dockerfile.test ."
13+
base_image = ENV["E2E_BASE_IMAGE"]
14+
build_cmd = "docker build -t agent -f Dockerfile.test ."
15+
if base_image && !base_image.empty?
16+
build_cmd = "docker build --build-arg BASE_IMAGE=#{base_image} -t agent -f Dockerfile.test ."
17+
end
18+
system build_cmd
1419
system "docker run --privileged --device /dev/ptmx --network=host -v /tmp/agent-temp-directory/:/tmp/agent-temp-directory -v /var/run/docker.sock:/var/run/docker.sock --name agent -tdi agent bash -c \"service ssh restart && export SEMAPHORE_AGENT_LOG_LEVEL=debug SEMAPHORE_AGENT_LOGS_COMPRESSION_SIZE=1048576 && nohup ./agent serve --port 30000 --auth-token-secret 'TzRVcspTmxhM9fUkdi1T/0kVXNETCi8UdZ8dLM8va4E' & sleep infinity\""
1520

1621
pingable = nil

test/e2e_support/docker-compose-listen.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ services:
55
build:
66
context: ../..
77
dockerfile: Dockerfile.test
8+
args:
9+
BASE_IMAGE: ${E2E_BASE_IMAGE:-python:3}
810
command: 'bash -c "service ssh restart && SEMAPHORE_AGENT_LOG_LEVEL=DEBUG ./agent start --config-file /tmp/agent/config.yaml"'
911
devices:
1012
- /dev/ptmx

0 commit comments

Comments
 (0)