1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-05 20:21:11 +03:00

CI: store and reuse OpenSSH Server docker image used for tests

Supersedes #588
Fixes #665
Closes #685
This commit is contained in:
Marc Hoersken
2022-03-16 04:29:31 +01:00
parent 292830abb8
commit 87d208c95d
5 changed files with 95 additions and 15 deletions

View File

@ -85,10 +85,8 @@ jobs:
cd bin
cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION ..
cmake --build .
pushd ../tests
docker build -t libssh2/openssh_server openssh_server
popd
CTEST_OUTPUT_ON_FAILURE=1 cmake --build . --target test
export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server)
ctest -VV --output-on-failure
cmake --build . --target package
fuzzer:
runs-on: ubuntu-latest

66
.github/workflows/openssh_server.yml vendored Normal file
View File

@ -0,0 +1,66 @@
# Copyright (c) 2022 Marc Hoersken
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
name: OpenSSH Server Docker Image
on:
push:
branches: [ master ]
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v1
- shell: bash
id: hash
run: echo "::set-output name=hash::$(git rev-parse --short=20 HEAD:tests/openssh_server)"
- shell: bash
id: poll
run: docker manifest inspect ghcr.io/${{ github.repository_owner }}/ci_tests_openssh_server:${{ steps.hash.outputs.hash }}
continue-on-error: true
- uses: docker/metadata-action@v3
id: meta
with:
images: ghcr.io/${{ github.repository_owner }}/ci_tests_openssh_server
tags: |
type=raw,value=${{ steps.hash.outputs.hash }}
if: ${{ steps.poll.outcome == 'failure' }}
- uses: docker/build-push-action@v2
with:
context: ./tests/openssh_server
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
if: ${{ steps.poll.outcome == 'failure' }}

View File

@ -112,10 +112,9 @@ script:
- |
if [ "$B" = "cmake" ]; then
mkdir bin
cd tests
docker build -t libssh2/openssh_server openssh_server
cd ../bin
cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. && cmake --build . && CTEST_OUTPUT_ON_FAILURE=1 cmake --build . --target test && cmake --build . --target package
cd bin
export OPENSSH_SERVER_IMAGE=ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:../tests/openssh_server)
cmake $TOOLCHAIN_OPTION -DCRYPTO_BACKEND=$CRYPTO_BACKEND -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DENABLE_ZLIB_COMPRESSION=$ENABLE_ZLIB_COMPRESSION .. && cmake --build . && ctest -VV --output-on-failure && cmake --build . --target package
fi
- |
if [ "$B" = "fuzzer" ]; then

View File

@ -103,8 +103,8 @@ before_test:
}
test_script:
- ps: cd _builds
- ps: ctest -VV -C $($env:CONFIGURATION) --output-on-failure
- ps: $env:OPENSSH_SERVER_IMAGE=[string] (& bash -c "echo ghcr.io/libssh2/ci_tests_openssh_server:$(git rev-parse --short=20 HEAD:tests/openssh_server)")
- ps: cd _builds; ctest -VV -C $($env:CONFIGURATION) --output-on-failure
on_failure:
- ps: if(Test-Path _builds/CMakeFiles/CMakeOutput.log) { cat _builds/CMakeFiles/CMakeOutput.log }

View File

@ -143,8 +143,26 @@ static int run_command(char **output, const char *command, ...)
return ret;
}
static const char *openssh_server_image(void)
{
return getenv("OPENSSH_SERVER_IMAGE");
}
static int build_openssh_server_docker_image(void)
{
const char *container_image_name = openssh_server_image();
if(container_image_name != NULL) {
int ret = run_command(NULL, "docker pull --quiet %s",
container_image_name);
if(ret == 0) {
ret = run_command(NULL, "docker tag %s libssh2/openssh_server",
container_image_name);
if(ret == 0) {
return ret;
}
}
}
return run_command(NULL, "docker build --quiet "
"-t libssh2/openssh_server "
"openssh_server");
@ -164,11 +182,10 @@ static int start_openssh_server(char **container_id_out)
"libssh2/openssh_server",
container_host_port);
}
else {
return run_command(container_id_out,
"docker run --rm -d -p 22 "
"libssh2/openssh_server");
}
return run_command(container_id_out,
"docker run --rm -d -p 22 "
"libssh2/openssh_server");
}
static int stop_openssh_server(char *container_id)