From e061a933f65d4d0c2b5dd8085170c8165d0f3f97 Mon Sep 17 00:00:00 2001 From: Hikaru Kawayoke Date: Fri, 11 Oct 2019 17:02:30 +0900 Subject: [PATCH] initial commit --- Dockerfile | 12 ++++++++++++ README.md | 24 ++++++++++++++++++++++++ action.yaml | 6 ++++++ entrypoint.sh | 28 ++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 action.yaml create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..df116e4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +# Container image that runs your code +FROM ubuntu:18.04 + +# Copies your code file from your action repository to the filesystem path `/` of the container +COPY entrypoint.sh /entrypoint.sh + +RUN apt-get update && apt-get install -y \ + zip \ + sshpass + +# Code file to execute when the docker container starts up (`entrypoint.sh`) +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..0b90ffb --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# ZIP Deploy Action +This action creates a zip file of a repository and upload it to a server and then unzip it in a specified location +## Usage +``` +name: CI +on: + push: + branches: + - master +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Deploy + uses: y0ke/ZIP-Deploy-Action@master + env: + LOCAL_DIR: DIRECTORY_TO_DEPLOY + REMOTE_DIR: REMOTE_DIR_TO_PUT + EXCLUDE: "tests/* .gitattributes .gitignore" + TARGET_SERVER: ${{ secrets.SERVER_NAME }} + DEPLOY_USERNAME: ${{ secrets.DEPLOY_USERNAME }} + DEPLOY_PASSWORD: ${{ secrets.DEPLOY_PASSWORD }} +``` \ No newline at end of file diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..7c1d5af --- /dev/null +++ b/action.yaml @@ -0,0 +1,6 @@ +# action.yml +name: 'zipSCPAction' +description: 'Zip all files and deploy them to a server.' +runs: + using: 'docker' + image: 'Dockerfile' \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..66bc817 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,28 @@ +#!/bin/sh -l + +M_LOCAL_DIR=${LOCAL_DIR:-"./"} +M_REMOTE_DIR=${REMOTE_DIR:-"~/"} +M_TMP_DIR=${TMP_DIR:-"~/"} + +echo "Creating a zip files..." +cd $M_LOCAL_DIR +zip ~/dist.zip -r ./ -x \*/.git/\* $EXCLUDE +cd ~/ +echo "Zip file created." + + +echo "Deploying files" + +sshpass -p $DEPLOY_PASSWORD scp -o StrictHostKeyChecking=no dist.zip ${DEPLOY_USERNAME}@${TARGET_SERVER}:${M_TMP_DIR} + +sshpass -p $DEPLOY_PASSWORD ssh ${DEPLOY_USERNAME}@${TARGET_SERVER} bash -c "' +cd ${M_TMP_DIR} +rm -rf tmp_zip +mkdir tmp_zip +unzip dist.zip -d tmp_zip +cp -Rpf tmp_zip/. ${M_REMOTE_DIR} +rm -rf tmp_zip +rm dist.zip +'" + +echo "Deploy completed"