Skip to content

Commit af18827

Browse files
authored
Merge pull request mendhak#66 from mendhak/gha_caching
Github Actions caching and updates
2 parents a3d5655 + 98969a7 commit af18827

File tree

3 files changed

+62
-37
lines changed

3 files changed

+62
-37
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ jobs:
2222
# Steps represent a sequence of tasks that will be executed as part of the job
2323
steps:
2424
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
25-
- uses: actions/checkout@v3
25+
- uses: actions/checkout@v4
2626

2727
- name: Set up QEMU
28-
uses: docker/setup-qemu-action@v2
28+
uses: docker/setup-qemu-action@v3
2929
- name: Set up Docker Buildx
3030
id: buildx
31-
uses: docker/setup-buildx-action@v2
31+
uses: docker/setup-buildx-action@v3
3232

3333
- name: Inspect builder
3434
run: |
@@ -40,33 +40,46 @@ jobs:
4040
4141
- name: Docker metadata
4242
id: meta
43-
uses: docker/metadata-action@v4
43+
uses: docker/metadata-action@v5
4444
with:
4545
images: |
4646
mendhak/http-https-echo
4747
4848
- name: Build the image multi-platform
49-
uses: docker/build-push-action@v4
49+
uses: docker/build-push-action@v5
5050
with:
5151
context: .
5252
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le
5353
push: false
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max
5456
tags: ${{ steps.meta.outputs.tags }}
5557
labels: ${{ steps.meta.outputs.labels }}
5658

57-
- name: Build the image single platform and run tests
59+
# Due to bug https://github.com/docker/buildx/issues/59, need to build for single platform, load, then run tests.
60+
- name: Build a test image single platform and load it
61+
uses: docker/build-push-action@v5
62+
with:
63+
context: .
64+
push: false
65+
load: true
66+
cache-from: type=gha
67+
cache-to: type=gha,mode=max
68+
tags: "mendhak/http-https-echo:testing"
69+
labels: ${{ steps.meta.outputs.labels }}
70+
71+
- name: Run tests using the test image
5872
run: ./tests.sh
5973

6074
- name: Scan the image
6175
id: scan
6276
uses: anchore/scan-action@v3
6377
with:
6478
image: "mendhak/http-https-echo:latest"
65-
debug: false
66-
acs-report-enable: true
79+
output-format: sarif
6780
severity-cutoff: critical
6881

6982
- name: upload Anchore scan SARIF report
70-
uses: github/codeql-action/upload-sarif@v2
83+
uses: github/codeql-action/upload-sarif@v3
7184
with:
7285
sarif_file: ${{ steps.scan.outputs.sarif }}

.github/workflows/publish.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ jobs:
1111
publish:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515

1616
- name: Set up QEMU
17-
uses: docker/setup-qemu-action@v2
17+
uses: docker/setup-qemu-action@v3
1818

1919
- name: Set up Docker Buildx
2020
id: buildx
21-
uses: docker/setup-buildx-action@v2
21+
uses: docker/setup-buildx-action@v3
2222

2323
- name: Inspect builder
2424
run: |
@@ -29,32 +29,33 @@ jobs:
2929
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
3030
3131
- name: Log in to Docker Hub
32-
uses: docker/login-action@v2
32+
uses: docker/login-action@v3
3333
with:
3434
username: ${{ secrets.DOCKER_HUB_USERNAME }}
3535
password: ${{ secrets.DOCKER_HUB_TOKEN }}
3636

3737
- name: Log in to GitHub Container registry
38-
uses: docker/login-action@v2
38+
uses: docker/login-action@v3
3939
with:
4040
registry: ghcr.io
4141
username: ${{ github.actor }}
4242
password: ${{ secrets.GITHUB_TOKEN }}
4343

4444
- name: Docker metadata
4545
id: meta
46-
uses: docker/metadata-action@v4
46+
uses: docker/metadata-action@v5
4747
with:
4848
images: |
4949
mendhak/http-https-echo
5050
ghcr.io/mendhak/http-https-echo
5151
5252
- name: Build and push image
53-
uses: docker/build-push-action@v4
53+
uses: docker/build-push-action@v5
5454
with:
5555
context: .
5656
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le
5757
push: true
5858
tags: ${{ steps.meta.outputs.tags }}
5959
labels: ${{ steps.meta.outputs.labels }}
60-
output: type=image,name=target,annotation-index.org.opencontainers.image.description=Docker image that echoes request data as JSON, listens on HTTP/S, with various extra features, useful for debugging.
60+
cache-from: type=gha
61+
cache-to: type=gha,mode=max

tests.sh

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,19 @@ if ! [ -x "$(command -v jq)" ]; then
2626
sudo apt -y install jq
2727
fi
2828

29-
message " Build image "
30-
docker build -t mendhak/http-https-echo:latest .
29+
message " Check if we're in Github Actions or local run "
30+
if [ -n "${GITHUB_ACTIONS:-}" ]; then
31+
echo " Github Actions. Image should already be built."
32+
docker images
33+
if [ -z "$(docker images -q mendhak/http-https-echo:testing 2> /dev/null)" ]; then
34+
echo "Docker image mendhak/http-https-echo:testing not found. Exiting."
35+
exit 1
36+
fi
37+
else
38+
echo " Local run. Build image "
39+
docker build -t mendhak/http-https-echo:testing .
40+
fi
41+
3142

3243
mkdir -p testarea
3344
pushd testarea
@@ -36,7 +47,7 @@ message " Cleaning up from previous test run "
3647
docker ps -aq --filter "name=http-echo-tests" | grep -q . && docker stop http-echo-tests && docker rm -f http-echo-tests
3748

3849
message " Start container normally "
39-
docker run -d --rm --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
50+
docker run -d --rm --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
4051
sleep 5
4152

4253

@@ -149,7 +160,7 @@ docker stop http-echo-tests
149160
sleep 5
150161

151162
message " Start container with different internal ports "
152-
docker run -d --rm -e HTTP_PORT=8888 -e HTTPS_PORT=9999 --name http-echo-tests -p 8080:8888 -p 8443:9999 -t mendhak/http-https-echo
163+
docker run -d --rm -e HTTP_PORT=8888 -e HTTPS_PORT=9999 --name http-echo-tests -p 8080:8888 -p 8443:9999 -t mendhak/http-https-echo:testing
153164
sleep 5
154165

155166
message " Make http(s) request, and test the path, method and header. "
@@ -183,7 +194,7 @@ docker stop http-echo-tests
183194
sleep 5
184195

185196
message " Start container with empty responses "
186-
docker run -d --rm -e ECHO_BACK_TO_CLIENT=false --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
197+
docker run -d --rm -e ECHO_BACK_TO_CLIENT=false --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
187198
sleep 5
188199
REQUEST=$(curl -s -k http://localhost:8080/a/b/c)
189200
if [[ -z ${REQUEST} ]]
@@ -200,7 +211,7 @@ docker stop http-echo-tests
200211
sleep 5
201212

202213
message " Start container with response body only "
203-
docker run -d --rm --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
214+
docker run -d --rm --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
204215
sleep 5
205216
RESPONSE=$(curl -s -k -X POST -d 'cauliflower' http://localhost:8080/a/b/c?response_body_only=true)
206217
if [[ ${RESPONSE} == "cauliflower" ]]
@@ -218,7 +229,7 @@ docker stop http-echo-tests
218229
sleep 5
219230

220231
message " Start container with JWT_HEADER "
221-
docker run -d --rm -e JWT_HEADER=Authentication --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
232+
docker run -d --rm -e JWT_HEADER=Authentication --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
222233
sleep 5
223234

224235
REQUEST=$(curl -s -k -H "Authentication: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" https://localhost:8443/ )
@@ -239,7 +250,7 @@ sleep 5
239250

240251

241252
message " Start container with LOG_IGNORE_PATH "
242-
docker run -d --rm -e LOG_IGNORE_PATH=/ping --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
253+
docker run -d --rm -e LOG_IGNORE_PATH=/ping --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
243254
sleep 5
244255
curl -s -k -X POST -d "banana" https://localhost:8443/ping > /dev/null
245256

@@ -259,7 +270,7 @@ docker stop http-echo-tests
259270
sleep 5
260271

261272
message " Start container with DISABLE_REQUEST_LOGS "
262-
docker run -d --rm -e DISABLE_REQUEST_LOGS=true --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
273+
docker run -d --rm -e DISABLE_REQUEST_LOGS=true --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
263274
sleep 5
264275
curl -s -k -X GET https://localhost:8443/strawberry > /dev/null
265276
if [ $(docker logs http-echo-tests | grep -c "GET /strawberry HTTP/1.1") -eq 0 ]
@@ -278,7 +289,7 @@ sleep 5
278289
message " Start container with CORS_CONFIG"
279290
docker run -d --rm \
280291
-e CORS_ALLOW_ORIGIN="http://example.com" -e CORS_ALLOW_HEADERS="x-custom-test-header" \
281-
--name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
292+
--name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
282293
sleep 5
283294
# Check if the expected CORS headers are present in the response
284295
if curl -s -i http://localhost:8080/ 2>&1 | grep -q -E \
@@ -297,7 +308,7 @@ docker stop http-echo-tests
297308
sleep 5
298309

299310
message " Start container with LOG_WITHOUT_NEWLINE "
300-
docker run -d --rm -e LOG_WITHOUT_NEWLINE=1 --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
311+
docker run -d --rm -e LOG_WITHOUT_NEWLINE=1 --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
301312
sleep 5
302313
curl -s -k -X POST -d "tiramisu" https://localhost:8443/ > /dev/null
303314

@@ -317,7 +328,7 @@ docker stop http-echo-tests
317328
sleep 5
318329

319330
message " Check that container is running as a NON ROOT USER by default"
320-
docker run -d --name http-echo-tests --rm mendhak/http-https-echo
331+
docker run -d --name http-echo-tests --rm mendhak/http-https-echo:testing
321332

322333
WHOAMI=$(docker exec http-echo-tests whoami)
323334

@@ -334,9 +345,9 @@ docker stop http-echo-tests
334345
sleep 5
335346

336347
message " Check that container is running as user different that the user defined in image"
337-
IMAGE_USER="$(docker image inspect mendhak/http-https-echo -f '{{ .Config.User }}')"
348+
IMAGE_USER="$(docker image inspect mendhak/http-https-echo:testing -f '{{ .Config.User }}')"
338349
CONTAINER_USER="$((IMAGE_USER + 1000000))"
339-
docker run -d --name http-echo-tests --rm -u "${CONTAINER_USER}" -p 8080:8080 mendhak/http-https-echo
350+
docker run -d --name http-echo-tests --rm -u "${CONTAINER_USER}" -p 8080:8080 mendhak/http-https-echo:testing
340351
sleep 5
341352
curl -s http://localhost:8080 > /dev/null
342353

@@ -359,7 +370,7 @@ message " Check that mTLS server responds with client certificate details"
359370
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout privkey.pem -out fullchain.pem \
360371
-subj "/CN=client.example.net" \
361372
-addext "subjectAltName=DNS:client.example.net"
362-
docker run -d --rm -e MTLS_ENABLE=1 --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
373+
docker run -d --rm -e MTLS_ENABLE=1 --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
363374
sleep 5
364375
COMMON_NAME="$(curl -sk --cert fullchain.pem --key privkey.pem https://localhost:8443/ | jq -r '.clientCertificate.subject.CN')"
365376
SAN="$(curl -sk --cert fullchain.pem --key privkey.pem https://localhost:8443/ | jq -r '.clientCertificate.subjectaltname')"
@@ -412,7 +423,7 @@ docker run -d --rm \
412423
-e HTTPS_CERT_FILE="${container_https_cert_file}" \
413424
-v "${https_key_file}:${container_https_key_file}:ro,z" \
414425
-e HTTPS_KEY_FILE="${container_https_key_file}" \
415-
--name http-echo-tests -p 8443:8443 -t mendhak/http-https-echo
426+
--name http-echo-tests -p 8443:8443 -t mendhak/http-https-echo:testing
416427
sleep 5
417428

418429
REQUEST_WITH_STATUS_CODE="$(curl -s --cacert "$(pwd)/server_fullchain.pem" -o /dev/null -w "%{http_code}" \
@@ -430,7 +441,7 @@ docker stop http-echo-tests
430441
sleep 5
431442

432443
message " Check that environment variables returned in response if enabled"
433-
docker run -d --rm -e ECHO_INCLUDE_ENV_VARS=1 --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
444+
docker run -d --rm -e ECHO_INCLUDE_ENV_VARS=1 --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
434445
sleep 5
435446
RESPONSE_BODY="$(curl -sk https://localhost:8443/ | jq -r '.env.ECHO_INCLUDE_ENV_VARS')"
436447

@@ -447,7 +458,7 @@ docker stop http-echo-tests
447458
sleep 5
448459

449460
message " Check that environment variables are not present in response by default"
450-
docker run -d --rm --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
461+
docker run -d --rm --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
451462
sleep 5
452463
RESPONSE_BODY_ENV_CHECK="$(curl -sk https://localhost:8443/ | jq 'has("env")')"
453464

@@ -464,7 +475,7 @@ docker stop http-echo-tests
464475
sleep 5
465476

466477
message " Start container with PROMETHEUS disabled "
467-
docker run -d --rm --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
478+
docker run -d --rm --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
468479
sleep 5
469480
curl -s -k -X POST -d "tiramisu" https://localhost:8443/ > /dev/null
470481

@@ -485,7 +496,7 @@ docker stop http-echo-tests
485496
sleep 5
486497

487498
message " Start container with PROMETHEUS enabled "
488-
docker run -d -e PROMETHEUS_ENABLED=true --rm --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo
499+
docker run -d -e PROMETHEUS_ENABLED=true --rm --name http-echo-tests -p 8080:8080 -p 8443:8443 -t mendhak/http-https-echo:testing
489500
sleep 5
490501
curl -s -k -X POST -d "tiramisu" https://localhost:8443/ > /dev/null
491502

0 commit comments

Comments
 (0)