From a9382b67a2f81058872f8c4f0c969af4ffa4ef66 Mon Sep 17 00:00:00 2001 From: Dragan Filipovic Date: Thu, 29 Dec 2022 23:14:51 +0100 Subject: [PATCH] e2e docker --- .github/workflows/e2e.yml | 72 +++++++++++++++++++++++++++++++++++ .github/workflows/example.yml | 46 ---------------------- test/.dockerignore | 5 +++ test/Dockerfile | 11 ++++++ 4 files changed, 88 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/e2e.yml delete mode 100644 .github/workflows/example.yml create mode 100644 test/.dockerignore create mode 100644 test/Dockerfile diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml new file mode 100644 index 0000000..94bf786 --- /dev/null +++ b/.github/workflows/e2e.yml @@ -0,0 +1,72 @@ +name: e2e Test + +on: + push: + branches: + - feature/add-tests + +env: + TEST_PROJECT: ./test_project + TEST_HOST_DOCKER: ./test + TEST_USER: kaja + REMOTE_USER: '' + REMOTE_PORT: '' + ARGS: '' + SOURCE: '' + TARGET: '' + EXCLUDE: '' + +jobs: + e2e: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: 1. Create ssh keys + run: | + ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N "" + EXAMPLE_SSH_PRIVATE_KEY=$(cat $HOME/.ssh/id_rsa) + echo "EXAMPLE_SSH_PRIVATE_KEY=$EXAMPLE_SSH_PRIVATE_KEY" >> $GITHUB_ENV + ssh-add "$HOME/.ssh/id_rsa" + ssh-add -l + + - name: Build Host Server Image + working-directory: $TEST_HOST_DOCKER + run: | + docker build \ + -t ssh-host-image . \ + --build-arg ssh_pub_key="$(cat $HOME/.ssh/id_rsa.pub)" \ + --build-arg ssh_user=$TEST_USER \ + + - name: Start Host Server Container + working-directory: $TEST_HOST_DOCKER + run: | + docker run --name ssh-host-container -d ssh-host-image + + - name: Get IP of Host Server + run: | + docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ssh-host-container > ip.txt + cat ip.txt + EXAMPLE_REMOTE_HOST=$(cat ip.txt) + echo "EXAMPLE_REMOTE_HOST=$EXAMPLE_REMOTE_HOST" >> $GITHUB_ENV + + - name: Create project file + run: | + mkdir $TEST_PROJECT && cd $TEST_PROJECT + touch index.html + date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html + cat index.html + + - name: e2e Test ssh-deploy action + uses: easingthemes/ssh-deploy@main + env: + SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY + ARGS: "-rltgoDzvO" + SOURCE: "dist/" + REMOTE_HOST: $EXAMPLE_REMOTE_HOST + REMOTE_USER: $TEST_USER + TARGET: "/var/www/html/" + EXCLUDE: "/dist/, /node_modules/" + diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml deleted file mode 100644 index 62678e3..0000000 --- a/.github/workflows/example.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: e2e Test - -on: - push: - branches: - - feature/add-tests - -env: - TEST_PROJECT: ./test_project - EXAMPLE_REMOTE_HOST: - REMOTE_USER: - REMOTE_PORT: - ARGS: - SOURCE: - TARGET: - EXCLUDE: '' - - -jobs: - host: - - runs-on: ${{ matrix.os }} - - strategy: - matrix: - os: [ ubuntu-latest ] - - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Get Host info - run: | - ls -l - ip addr show - whoami - - name: 1. Create ssh keys - run: | - ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N "" - shell: bash - - name: Create project file - run: | - mkdir $TEST_PROJECT && cd $TEST_PROJECT - touch index.html - date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html - cat index.html - shell: bash diff --git a/test/.dockerignore b/test/.dockerignore new file mode 100644 index 0000000..a612c4f --- /dev/null +++ b/test/.dockerignore @@ -0,0 +1,5 @@ +/node_modules +.gitignore +.gitattributes +LICENSE +README.md \ No newline at end of file diff --git a/test/Dockerfile b/test/Dockerfile new file mode 100644 index 0000000..babab6a --- /dev/null +++ b/test/Dockerfile @@ -0,0 +1,11 @@ +FROM nginx +# Set args to get from Gtihub Action +ARG ssh_pub_key +ARG ssh_user +# Add a user to the container +RUN adduser -D $ssh_user +USER $ssh_user +# Add the ssh public key to the container +RUN mkdir -p $HOME/.ssh +RUN echo "$ssh_pub_key" > $HOME/.ssh/authorized_keys +RUN chmod 700 $HOME/.ssh