main
Dragan Filipovic 2022-12-31 02:43:17 +01:00
parent fd8e654d7e
commit aeee708bee
6 changed files with 85 additions and 49 deletions

View File

@ -5,8 +5,9 @@ on:
branches: [ 'feature/add-tests' ]
env:
GLOBAL_WORKFLOW_ENV: __some value for GLOBAL_WORKFLOW_ENV__
TEST_HOST_DOCKER: ./test
TEST_USER: kaja
TEST_USER: test
jobs:
e2e:
@ -16,6 +17,25 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
# - name: Set ENV var
# run: |
# echo "CUSTOM_VAR=IT WORKS" >> $GITHUB_ENV
# - name: Use ENV var via `env` block
# run: |
# echo $CUSTOM_VAR # OK
# echo ${{ env.CUSTOM_VAR }} # OK
# echo $USE_CUSTOM_VAR # NOT OK, prints ''
# echo ${{ env.USE_CUSTOM_VAR }} # NOT OK, prints ''
# echo $USE_CUSTOM_VAR_2 # NOT OK, prints '$CUSTOM_VAR'
# echo ${{ env.USE_CUSTOM_VAR_2 }} # OK
# echo $USE_CUSTOM_VAR_3 # NOT OK, prints '$GLOBAL_WORKFLOW_ENV'
# echo ${{ env.USE_CUSTOM_VAR_3 }} # OK
# env:
# USE_CUSTOM_VAR: ${{ env.CUSTOM_VAR }}
# USE_CUSTOM_VAR_2: $CUSTOM_VAR
# USE_CUSTOM_VAR_3: $GLOBAL_WORKFLOW_ENV
- name: Clean up old test files
run: |
docker stop ssh-host-container || true && docker rm ssh-host-container || true
@ -37,9 +57,9 @@ jobs:
run: |
docker build \
-t ssh-host-image . \
--build-arg ssh_pub_key="$(cat $HOME/.ssh/id_rsa.pub)" \
--build-arg SSH_PUB_KEY="$(cat $HOME/.ssh/id_rsa.pub)" \
--build-arg ssh_user="${{ env.TEST_USER }}"
docker run -d --name=ssh-host-container ssh-host-image
docker run -d -p 8822:22 --name=ssh-host-container ssh-host-image
docker exec ssh-host-container sh -c "hostname --ip-address" > ip.txt
echo "EXAMPLE_REMOTE_HOST<<EOF" >> $GITHUB_ENV
cat ip.txt >> $GITHUB_ENV
@ -54,35 +74,36 @@ jobs:
date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html
cat index.html
- name: e2e Test ssh
run: |
ssh ${{ env.REMOTE_USER }}@${{ env.REMOTE_HOST }}
env:
REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }}
REMOTE_USER: ${{ env.TEST_USER }}
# - name: e2e Test local ssh-deploy action
# run: |
# echo "${{ env.REMOTE_HOST }} -- $EXAMPLE_REMOTE_HOST -- ${{ env.EXAMPLE_REMOTE_HOST }}"
# npm ci
# npm run build
# node ./src/test.js || true
# env:
# SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY
# ARGS: "-rltgoDzvO"
# SOURCE: "test_project/"
# REMOTE_HOST: $EXAMPLE_REMOTE_HOST
# REMOTE_USER: ${{ env.TEST_USER }}
# TARGET: "/var/www/html/"
# EXCLUDE: "/dist/, /node_modules/"
- name: e2e Test local ssh-deploy action
run: |
npm ci
npm run build
node ./src/index.js || true
env:
SSH_PRIVATE_KEY: ${{ env.EXAMPLE_SSH_PRIVATE_KEY }}
ARGS: "-rltgoDzvO"
SOURCE: "test_project/"
REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }}
REMOTE_USER: ${{ env.TEST_USER }}
TARGET: "/var/www/html/"
EXCLUDE: "/dist/, /node_modules/"
# - name: e2e Test ssh
# run: |
# echo "$SSH_REMOTE_USER@$SSH_REMOTE_HOST"
# ssh -p 8822 $SSH_REMOTE_USER@$SSH_REMOTE_HOST 'exit'
# env:
# SSH_REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }}
# SSH_REMOTE_USER: ${{ env.TEST_USER }}
- name: e2e Test published ssh-deploy action
uses: easingthemes/ssh-deploy@main
env:
SSH_PRIVATE_KEY: ${{ env.EXAMPLE_SSH_PRIVATE_KEY }}
with:
SSH_PRIVATE_KEY: $EXAMPLE_SSH_PRIVATE_KEY
ARGS: "-rltgoDzvO"
SOURCE: "test_project/"
REMOTE_HOST: ${{ env.EXAMPLE_REMOTE_HOST }}
REMOTE_HOST: $EXAMPLE_REMOTE_HOST
REMOTE_USER: ${{ env.TEST_USER }}
TARGET: "/var/www/html/"
EXCLUDE: "/dist/, /node_modules/"

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,9 @@ const inputs = {
GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE
};
// Get inputs from ENV or WITH workflow settings
console.log('EXAMPLE_REMOTE_HOST: ', process.env.EXAMPLE_REMOTE_HOST);
console.log('REMOTE_HOST: ', process.env.REMOTE_HOST);
inputNames.forEach((input) => {
inputs[input] = process.env[input] || process.env[`INPUT_${input}`];
});

View File

@ -1,9 +1,2 @@
const {
REMOTE_HOST, REMOTE_USER,
REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME,
SOURCE, TARGET, ARGS, EXCLUDE,
GITHUB_WORKSPACE
} = require('./inputs');
// eslint-disable-next-line max-len
console.log(REMOTE_HOST, REMOTE_USER, REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME, SOURCE, TARGET, ARGS, EXCLUDE, GITHUB_WORKSPACE);
console.log('EXAMPLE_REMOTE_HOST: ', process.env.EXAMPLE_REMOTE_HOST);
console.log('REMOTE_HOST: ', process.env.REMOTE_HOST);

View File

@ -1,15 +1,31 @@
FROM nginx
# Set args to get from Gtihub Action
ARG ssh_pub_key
ARG ssh_user
# Add a user to the container
RUN adduser --disabled-password $ssh_user
# USER $ssh_user
# Add the ssh public key to the container
RUN mkdir -p /home/$ssh_user/.ssh
RUN echo "$ssh_pub_key" > /home/$ssh_user/.ssh/authorized_keys
RUN chmod 700 /home/$ssh_user/.ssh
# Start server
EXPOSE 80
STOPSIGNAL SIGTERM
ARG SSH_PUB_KEY
RUN apt update
RUN apt install openssh-server sudo -y
RUN useradd -rm -d /home/test -s /bin/bash -g root -G sudo -u 1000 test
RUN usermod -aG sudo test
RUN echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config.d/pub.conf
RUN echo "AuthorizedKeysFile .ssh/authorized_keys" >> /etc/ssh/sshd_config.d/pub.conf
RUN mkdir -p /home/test/.ssh
RUN echo "$SSH_PUB_KEY" > /home/test/.ssh/authorized_keys
RUN chmod 700 /home/test/.ssh
RUN chown -R test /home/test/.ssh
RUN service ssh start
RUN echo 'test:test' | chpasswd
EXPOSE 22
ADD entrypoint.sh /docker-entrypoint.d/entrypoint.sh
RUN chmod +x /docker-entrypoint.d/entrypoint.sh
CMD ["nginx", "-g", "daemon off;"]

3
test/entrypoint.sh Normal file
View File

@ -0,0 +1,3 @@
#!/bin/bash
/usr/sbin/sshd -D