Skip to content

Commit

Permalink
Trying to implement local testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Aug 19, 2024
1 parent 5435d2b commit 2cc3628
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**
!test
!proxy/nginx.conf
!install.sh
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# limitations under the License.
#

ARG METACALL_INSTALL_CERTS=debian_certs_local

FROM scratch AS testing

# Image descriptor
Expand All @@ -27,15 +29,28 @@ LABEL copyright.name="Vicente Eduardo Ferrer Garcia" \
vendor="MetaCall Inc." \
version="0.1"

# Proxy certificates
FROM metacall/install_nginx AS debian_certs_local

# Remote certificates
FROM debian:bookworm-slim AS debian_certs_remote

RUN mkdir -p /etc/ssl/certs/

FROM ${METACALL_INSTALL_CERTS} AS debian_certs

# Debian Base (root)
FROM debian:bookworm-slim AS debian_root

COPY --from=debian_certs /etc/ssl/certs/ /etc/ssl/certs/

COPY test/ /test/

# Install dependencies and set up a sudo user without password
RUN apt-get update \
&& apt-get install -y --no-install-recommends sudo curl wget ca-certificates \
&& apt-get clean && rm -rf /var/lib/apt/lists/ \
&& update-ca-certificates \
&& adduser --disabled-password --gecos "" user \
&& usermod -aG sudo user \
&& echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
Expand Down
2 changes: 2 additions & 0 deletions proxy/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**
!nginx.conf
42 changes: 42 additions & 0 deletions proxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# MetaCall Install Script by Parra Studios
# Cross-platform set of scripts to install MetaCall infrastructure.
#
# Copyright (C) 2016 - 2024 Vicente Eduardo Ferrer Garcia <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

FROM nginx:alpine-slim AS proxy

# Image descriptor
LABEL copyright.name="Vicente Eduardo Ferrer Garcia" \
copyright.address="[email protected]" \
maintainer.name="Vicente Eduardo Ferrer Garcia" \
maintainer.address="[email protected]" \
vendor="MetaCall Inc." \
version="0.1"

COPY install.sh /usr/share/nginx/html/
COPY proxy/nginx.conf /etc/nginx/

RUN apk add openssl \
&& openssl req -x509 -nodes -days 365 -subj "/C=CA/ST=QC/O=Company, Inc./CN=raw.githubusercontent.com" \
-addext "subjectAltName=DNS:raw.githubusercontent.com" -newkey rsa:2048 \
-keyout /etc/ssl/private/nginx-selfsigned.key \
-out /etc/ssl/certs/nginx-selfsigned.crt

USER root

EXPOSE 80
EXPOSE 443
32 changes: 32 additions & 0 deletions proxy/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
user root;
worker_processes 1;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
sendfile on;
keepalive_timeout 65;

server {
listen 80;
listen [::]:80;
server_name raw.githubusercontent.com;

listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;

location /metacall/install/master/install.sh {
alias /usr/share/nginx/html/install.sh;
types {
application/x-sh sh;
}
default_type application/x-sh;
}
}
}
39 changes: 37 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,47 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -euox pipefail

# Run with Buildkit
export DOCKER_BUILDKIT=1

# Get current root folder
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)

# Get test list (any target prefixed by 'test_')
TEST_LIST=$(cat Dockerfile | grep -v '^#' | grep 'AS test_' | awk '{print $4}')

# Run a local server static file server for tricking the tests into using the
# current version of install.sh script instead the one from GitHub URL
docker build -t metacall/install_nginx -f proxy/Dockerfile .

docker run --rm \
--name metacall_install_nginx \
-p 80:80 \
-p 443:443 \
--network host \
-d metacall/install_nginx

# Define default certificate setup
METACALL_INSTALL_CERTS="${METACALL_INSTALL_CERTS:-debian_certs_remote}"

if [[ "${METACALL_INSTALL_CERTS}" = "debian_certs_local" ]]; then
METACALL_INSTALL_DNS=--add-host="raw.githubusercontent.com:127.0.0.1"
else
METACALL_INSTALL_DNS=
fi

# Run tests
for test in ${TEST_LIST}; do
docker build --no-cache --progress=plain --target ${test} -t metacall/install:${test} .
docker build \
--no-cache \
--progress=plain \
--target ${test} \
--build-arg "METACALL_INSTALL_CERTS=${METACALL_INSTALL_CERTS}" \
--network host \
${METACALL_INSTALL_DNS} \
-t metacall/install:${test} .
result=$?
if [[ $result -ne 0 ]]; then
echo "Test ${test} failed. Abort."
Expand All @@ -36,8 +68,11 @@ for test in ${TEST_LIST}; do
docker system prune -f --all
done

# Clear the proxy
docker stop metacall_install_nginx

# Test Docker Install
DOCKER_HOST_PATH=`pwd`/test
DOCKER_HOST_PATH="${SCRIPT_DIR}/test"

# Run Docker install with --docker-install parameter
docker run --rm \
Expand Down

0 comments on commit 2cc3628

Please sign in to comment.