Skip to content

Commit

Permalink
ci:
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyTubongbanua committed Jul 4, 2023
1 parent 8ddd7fb commit a4776e6
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/end2end_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
env:
SSHNP_ATSIGN: "@jeremy_0"
SSHNPD_ATSIGN: "@smoothalligator"
CONTAINER_TIMEOUT: "30"
CONTAINER_TIMEOUT: "300" # seconds

jobs:
end2end_tests_trunk:
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Docker Compose Up
working-directory: packages/sshnoports/test/end2end_tests
run: |
docker compose up --abort-on-container-exit --exit-code-from=container-trunk-sshnp --wait-timeout=${{ env.CONTAINER_TIMEOUT }} --always-recreate-deps
docker compose up --abort-on-container-exit --exit-code-from=container-trunk-sshnp -t=${{ env.CONTAINER_TIMEOUT }}
- name: (Debug) View containers
continue-on-error: true # in case step fails, pass anyway
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
sleep 10
sleep 2
~/.local/bin/sshnp -f @jeremy_0 -t @smoothalligator -d docker -h @rv_am -s id_ed25519.pub -v
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
#!/bin/bash
# tmux new-session -d -s sshnpd
# tmux send-keys -t sshnpd "~/.local/bin/sshnpd -a @smoothalligator -m @jeremy_0 -d docker -s -u -v" C-m
# sleep 2

~/.local/bin/sshnpd -a @smoothalligator -m @jeremy_0 -d docker -s -u -v
sleep 2
~/.local/bin/sshnpd -a @smoothalligator -m @jeremy_0 -d docker -s -u -v
31 changes: 31 additions & 0 deletions packages/sshnoports/test/end2end_tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
version: '3'

services:
# image-runtime-blank:
# build:
# context: ./image/
# dockerfile: ./Dockerfile
# target: runtime-blank
# image: atsigncompany/sshnp-e2e-runtime:blank
# deploy:
# mode: replicated
# replicas: 0
# image-runtime-local:
# build:
# context: ./image/
# dockerfile: ./Dockerfile
# target: runtime-release
# args:
# - release=3.3.0
# image: atsigncompany/sshnp-e2e-runtime:local
# deploy:
# mode: replicated
# replicas: 0
# image-runtime-release:
# build:
# context: ./image/
# dockerfile: ./Dockerfile
# target: runtime-release
# args:
# - release=3.3.0
# image: atsigncompany/sshnp-e2e-runtime:release
# deploy:
# mode: replicated
# replicas: 0
image-runtime-trunk:
build:
context: ./image/
Expand Down
79 changes: 53 additions & 26 deletions packages/sshnoports/test/end2end_tests/image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ ENV OUTPUT_DIR=/app/output

ARG branch=trunk

RUN mkdir -p ${REPO_DIR} ${OUTPUT_DIR} ; \
RUN set -eux ; \
mkdir -p ${REPO_DIR} ${OUTPUT_DIR} ; \
apt-get update ; \
apt-get install -y git ; \
cd ${REPO_DIR} ; \
Expand All @@ -16,8 +17,8 @@ RUN mkdir -p ${REPO_DIR} ${OUTPUT_DIR} ; \
dart compile exe ${REPO_DIR}/packages/sshnoports/bin/sshnp.dart -o ${OUTPUT_DIR}/sshnp ; \
dart compile exe ${REPO_DIR}/packages/sshnoports/bin/sshnpd.dart -o ${OUTPUT_DIR}/sshnpd ; \
dart compile exe ${REPO_DIR}/packages/sshnoports/bin/sshrv.dart -o ${OUTPUT_DIR}/sshrv ; \
dart compile exe ${REPO_DIR}/packages/sshnoports/bin/sshrvd.dart -o ${BUILDDIR}/bin/sshrvd ; \
dart compile exe ${REPO_DIR}/packages/sshnoports/bin/activate_cli.dart -o ${BUILDDIR}/bin/at_activate ;
dart compile exe ${REPO_DIR}/packages/sshnoports/bin/sshrvd.dart -o ${OUTPUT_DIR}/sshrvd ; \
dart compile exe ${REPO_DIR}/packages/sshnoports/bin/activate_cli.dart -o ${OUTPUT_DIR}/at_activate ;

FROM dart:3.0.5@sha256:65e5f5d6d72ad2f7b32f402c01b5fe8a426455b1ede1e9f840f95a2a8c14afbd AS build-local

Expand All @@ -29,7 +30,8 @@ RUN mkdir -p ${REPO_DIR} ${OUTPUT_DIR} ;
# context must be the same folder as the Dockerfile
COPY ../../../ ${REPO_DIR}

RUN cd ${REPO_DIR} ; \
RUN set -eux ; \
cd ${REPO_DIR} ; \
dart pub get ; \
dart compile exe ${REPO_DIR}/bin/sshnp.dart -o ${OUTPUTDIR}/sshnp ; \
dart compile exe ${REPO_DIR}/bin/sshnpd.dart -o ${OUTPUTDIR}/sshnpd ; \
Expand All @@ -39,34 +41,39 @@ RUN cd ${REPO_DIR} ; \

FROM debian:stable-20230612-slim@sha256:b09f68bffcf9c14f3105f262e92321d05abaf48460d1f43f884325bcd4395b95 AS build-release

ARG release="3.3.0"
ARG release

RUN mkdir -p ${HOMEDIR}/.atsign/keys ${HOMEDIR}/.local/bin ${HOMEDIR}/tmp/build ; \
cd ${HOMEDIR}/tmp/build ; \
ENV BUILD_DIR=/app/build
ENV OUTPUT_DIR=/app/output
ENV URL="https://api.github.com/repos/atsign-foundation/sshnoports/releases/latest"
ENV URLP="https://github.com/atsign-foundation/sshnoports/releases/download"

RUN apt-get update ; \
apt-get install -y wget dpkg ; \
mkdir -p ${BUILD_DIR} ${OUTPUT_DIR} ; \
cd ${BUILD_DIR} ; \
case "$(dpkg --print-architecture)" in \
amd64) \
ARCH="x64";; \
armhf) \
ARCH="arm";; \
arm64) \
ARCH="arm64";; \
riscv64) \
ARCH="riscv64";; \
amd64) \
ARCH="x64";; \
armhf) \
ARCH="arm";; \
arm64) \
ARCH="arm64";; \
riscv64) \
ARCH="riscv64";; \
esac; \
URL="https://api.github.com/repos/atsign-foundation/sshnoports/releases/latest"; \
URLP="https://github.com/atsign-foundation/sshnoports/releases/download"; \
if [ -z "${release}" ]; \
then \
LATEST_VERSION=$(curl --silent ${URL} | grep -Po '"tag_name": "v\K.*?(?=")') ; \
VERSION=${LATEST_VERSION} ; \
LATEST_VERSION=$(curl --silent ${URL} | grep -Po '"tag_name": "v\K.*?(?=")') ; \
VERSION=${LATEST_VERSION} ; \
else \
VERSION=${release} ; \
VERSION=${release} ; \
fi ; \
wget "${URLP}/v${VERSION}/sshnp-linux-${ARCH}.tgz" ; \
tar -xvf sshnp-linux-${ARCH}.tgz ; \
rm sshnp-linux-${ARCH}.tgz ; \
cd sshnp ; \
mv sshnp sshnpd sshrv sshrvd at_activate ${HOMEDIR}/.local/bin ;
mv sshnp sshnpd sshrv sshrvd at_activate ${OUTPUT_DIR} ;

FROM debian:stable-20230612-slim@sha256:b09f68bffcf9c14f3105f262e92321d05abaf48460d1f43f884325bcd4395b95 AS base

Expand All @@ -77,7 +84,7 @@ ENV GROUP_ID=1024

RUN set -eux ; \
apt-get update ; \
apt-get install -y openssh-server sudo wget curl openssh-server nano vim iproute2 nmap tmux git dpkg ; \
apt-get install -y openssh-server sudo vim nano iproute2 nmap tmux ; \
groupadd --gid ${GROUP_ID} ${USER} ; \
useradd --system --shell /bin/bash --home ${HOMEDIR} --uid ${USER_ID} --gid ${GROUP_ID} ${USER} ; \
usermod -aG sudo ${USER} ; \
Expand All @@ -89,20 +96,40 @@ RUN set -eux ; \
sed -E -i 's|^#?(PasswordAuthentication)\s.*|\1 no|' /etc/ssh/sshd_config ; \
sed -i 's/#ListenAddress 0.0.0.0/ListenAddress 127.0.0.1/g' /etc/ssh/sshd_config ;

FROM base AS blank
FROM base AS runtime-blank

WORKDIR ${HOMEDIR}

USER ${USER}

ENTRYPOINT sudo service ssh start && sh ${HOMEDIR}/entrypoint.sh

FROM blank AS runtime-branch
FROM base AS runtime-branch

COPY --chown=${USER}:${USER} --from=build-branch /app/output ${HOMEDIR}/.local/bin

FROM blank AS runtime-release
WORKDIR ${HOMEDIR}

USER ${USER}

ENTRYPOINT sudo service ssh start && sh ${HOMEDIR}/entrypoint.sh

FROM base AS runtime-release

COPY --chown=${USER}:${USER} --from=build-release /app/output ${HOMEDIR}/.local/bin

FROM blank AS runtime-local
WORKDIR ${HOMEDIR}

USER ${USER}

ENTRYPOINT sudo service ssh start && sh ${HOMEDIR}/entrypoint.sh

FROM base AS runtime-local

COPY --chown=${USER}:${USER} --from=build-local /app/output ${HOMEDIR}/.local/bin

WORKDIR ${HOMEDIR}

USER ${USER}

ENTRYPOINT sudo service ssh start && sh ${HOMEDIR}/entrypoint.sh
70 changes: 61 additions & 9 deletions packages/sshnoports/test/end2end_tests/tools/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
usage() {
echo "usage: $0"
echo " -h|--help"
echo " -t|--type <sshnp/sshnpd/sshrvd> (required)"
echo " -t|--tag <sshnp/sshnpd/sshrvd> (required)"
echo " ONE OF THE FOLLOWING (required)"
echo " -l|--local"
echo " -b|--branch <branch/commitid>"
Expand Down Expand Up @@ -33,7 +33,7 @@ parse_args() {
exit 0
;;
-t|--type)
type=$2
tag=$2
shift 2
;;
-l|--local)
Expand All @@ -60,28 +60,80 @@ parse_args() {
esac
done

if [[ -z $type ]];
# check that tag is provided
if [[ -z $tag ]];
then
echo "Missing required argument: --type"
echo "Missing required argument: --tag"
usage
exit 1
fi

if [[ $type != "sshnp" && $type != "sshnpd" && $type != "sshrvd" ]];
# check that tag is one of: sshnp/sshnpd/sshrvd
if [[ $tag != "sshnp" && $tag != "sshnpd" && $tag != "sshrvd" ]];
then
echo "Invalid type: $type, must be one of: sshnp/sshnpd/sshrvd"
echo "Invalid tag: $tag, must be one of: sshnp/sshnpd/sshrvd"
usage
exit 1
fi

# check that at least one of the following is provided: local branch release blank
if [[ -z $local && -z $branch && -z $release && -z $blank ]];
then
echo "Missing required argument: ONE OF THE FOLLOWING: --local, --branch, --release, --blank"
usage
exit 1
fi

# check that only one and only one of the following is provided: local branch release blank
local_count=0
branch_count=0
release_count=0
blank_count=0

if [[ ! -z $local ]];
then
type=local
local_count=1
fi

if [[ ! -z $branch ]];
then
type=branch
branch_count=1
fi

if [[ ! -z $release ]];
then
type=release
release_count=1
fi

if [[ ! -z $blank ]];
then
type=blank
blank_count=1
fi

if [[ $local_count + $branch_count + $release_count + $blank_count -gt 1 ]];
then
echo "Too many arguments provided: ONE OF THE FOLLOWING: --local, --branch, --release, --blank"
usage
exit 1
fi
}

main() {
# if type is branch
if [[ $type == "branch" ]];
then
sudo docker compose build --no-cache --build-arg branch=$branch
else if [[ $type == "release" ]]
sudo docker compose build --no-cache --build-arg release=$release
else
sudo docker compose build
fi

}

cd ..
sudo docker-compose up --exit-code-from=sshnp-trunk --build $@
sudo docker-compose down
parse_args $@
main

0 comments on commit a4776e6

Please sign in to comment.