From 44d4396a740d6be3856fdbf550b2e54a9fd42b9f Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 18 Oct 2019 10:27:01 -0500 Subject: [PATCH] fixed it --- Dockerfile | 38 ++++++------- README.md | 26 ++++++--- TEMPLATE/aws-config.yml | 12 ---- lib/entrypoint.sh | 121 +++++++++++++++++++++++----------------- 4 files changed, 108 insertions(+), 89 deletions(-) diff --git a/Dockerfile b/Dockerfile index fb906eb..24e4457 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,26 +22,27 @@ LABEL com.github.actions.name="NodeJS Deploy AWS Serverless" \ # Run the Update # ################## RUN apk add --no-cache \ - bash git musl-dev jq gcc curl + npm nodejs bash git musl-dev jq gcc curl RUN pip install --upgrade --no-cache-dir \ awscli aws-sam-cli yq -############################## -# Install NVM for all NodeJS # -############################## -ENV NVM_DIR /usr/local/nvm -ENV NODE_VERSION 10.16.3 - -RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash \ - && . $NVM_DIR/nvm.sh \ - && mkdir $NVM_DIR/versions \ - && nvm install $NODE_VERSION \ - && nvm alias default $NODE_VERSION \ - && nvm use default - -ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules -ENV PATH $NVM_DIR/v$NODE_VERSION/bin:$PATH +# Note: For now, we will use the builtin npm and nodejs +# ############################## +# # Install NVM for all NodeJS # +# ############################## +# ENV NVM_DIR /usr/local/nvm +# ENV NODE_VERSION 10.16.3 +# +# RUN curl https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash \ +# && . $NVM_DIR/nvm.sh \ +# && mkdir $NVM_DIR/versions \ +# && nvm install $NODE_VERSION \ +# && nvm alias default $NODE_VERSION \ +# && nvm use default +# +# ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules +# ENV PATH $NVM_DIR/v$NODE_VERSION/bin:$PATH #################################### # Setup AWS CLI Command Completion # @@ -53,10 +54,9 @@ RUN echo complete -C '/usr/local/bin/aws_completer' aws >> ~/.bashrc ########################################### ENV GITHUB_SHA=${GITHUB_SHA} ENV GITHUB_EVENT_PATH=${GITHUB_EVENT_PATH} -ENV GITHUB_TOKEN=${GITHUB_TOKEN} ENV GITHUB_WORKSPACE=${GITHUB_WORKSPACE} -ENV AWS_ACCESS_KEY=${AWS_ACCESS_KEY} -ENV AWS_SECRET_KEY=${AWS_SECRET_KEY} +ENV AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY} +ENV AWS_SECRET_ACCESS_KEY=${AWS_SECRET_KEY} ########################### # Copy files to container # diff --git a/README.md b/README.md index 393d25f..d5a095c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # deploy-nodejs This repository is for the **GitHub** Action to deploy a **NodeJS** application to **AWS** Serverless. -Developers on **GitHub** can call this Action to take their current **NodeJS** application, and pass basic variables to help deploy +Developers on **GitHub** can call this Action to take their current **NodeJS** application, and pass basic variables to help deploy thier application. ## How to use @@ -26,7 +26,7 @@ This file should have the following code: ## Deploy GitHub Actions ## ########################### ########################### -name: Deploy Action +name: NodeJS AWS SAM Deploy # # Documentation: @@ -44,9 +44,10 @@ on: ['push'] jobs: build: # Name the Job - name: Deploy NodeJS + name: NodeJS AWS SAM Deploy # Set the agent to run on runs-on: ubuntu-latest + ################## # Load all steps # ################## @@ -57,14 +58,23 @@ jobs: - name: Checkout Code uses: actions/checkout@master - ################## - # Run Deployment # - ################## - - name: Run Deployment - uses: github/deploy-nodejs@master + ############################# + # Run NodeJS AWS SAM Deploy # + ############################# + - name: NodeJS AWS SAM Deploy + uses: docker://admiralawkbar/aws-nodejs:latest + env: + AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }} + AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }} ... ``` +**NOTE:** You will need to create the GitHub `Secrets` for: +- **AWS_ACCESS_KEY** + - Valid AWS Access key to authenticate to your AWS Account +- **AWS_SECRET_KEY** + - Valid AWS Access Secret key to authenticate to your AWS Account + ## How to contribute If you would like to help contribute to this **Github** Action, please see [CONTRIBUTING](https://github.com/github/deploy-nodejs/blob/master/.github/CONTRIBUTING.md) diff --git a/TEMPLATE/aws-config.yml b/TEMPLATE/aws-config.yml index 00125a2..6028e2c 100644 --- a/TEMPLATE/aws-config.yml +++ b/TEMPLATE/aws-config.yml @@ -35,18 +35,6 @@ aws_stack_name: mystack # sam_template: .github/template.yml sam_template: -########################################### -# aws_access_key_id for connection to AWS # -########################################### -# NOTE: this AWS key needs all access to build and deploy SAM -aws_access_key_id: - -############################################### -# aws_secret_access_key for connection to AWS # -############################################### -# NOTE: this AWS key needs all access to build and deploy SAM -aws_secret_access_key: - ################################ # region for connection to AWS # ################################ diff --git a/lib/entrypoint.sh b/lib/entrypoint.sh index d020606..5fbc5e1 100755 --- a/lib/entrypoint.sh +++ b/lib/entrypoint.sh @@ -30,10 +30,10 @@ RUNTIME='' # Runtime for AWS SAM App ################### GITHUB_SHA="${GITHUB_SHA}" # GitHub sha from the commit GITHUB_EVENT_PATH="${GITHUB_EVENT_PATH}" # Github Event Path -GITHUB_TOKEN="${ACTIONS_RUNTIME_TOKEN}" # GitHub token +GITHUB_TOKEN='' # GitHub token GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace -AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" # aws_access_key_id to auth -AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" # aws_secret_access_key to auth +AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY}" # aws_access_key_id to auth +AWS_SECRET_ACCESS_KEY="${AWS_SECRET_KEY}" # aws_secret_access_key to auth GITHUB_URL='https://api.github.com' # GitHub API URL ############## @@ -41,8 +41,8 @@ GITHUB_URL='https://api.github.com' # GitHub API URL ############## GITHUB_ORG='' # Name of the GitHub Org GITHUB_REPO='' # Name of the GitHub repo -USER_CONFIG_FILE="$GITHUB_WORKSPACE/.github/aws-config.yml" # File with users configurations -START_DATE=$(date --utc "+%FT%T.%N" | sed -r 's/[[:digit:]]{7}$/Z/') # YYYY-MM-DDTHH:MM:SSZ +USER_CONFIG_FILE="$GITHUB_WORKSPACE/.github/aws-config.yml" # File with users configurations +START_DATE=$(date +"%Y-%m-%dT%H:%M:%SZ") # YYYY-MM-DDTHH:MM:SSZ FINISHED_DATE='' # YYYY-MM-DDTHH:MM:SSZ when complete ACTION_CONCLUSTION='' # success, failure, neutral, cancelled, timed_out, or action_required. ACTION_OUTPUT='' # String to pass back to the user on the output @@ -57,7 +57,9 @@ DEFAULT_REGION='us-west-2' # Default region to deploy LOCAL_CONFIG_FILE='/root/.aws/config' # AWS Config file LOCAL_CRED_FILE='/root/.aws/credentials' # AWS Credential file AWS_PACKAGED='packaged.yml' # Created SAM Package -NVM_SRC='/usr/local/nvm/nvm.sh' # Source for NVM +DEBUG=0 # Debug=0 OFF | Debug=1 ON +#NVM_SRC='/usr/local/nvm/nvm.sh' # Source for NVM + ###################################################### # Variables we need to set in the ~/.aws/credentials # @@ -267,31 +269,6 @@ CreateLocalConfiguration() ERROR_CAUSE='Failed to create root directory!' fi - ############################################ - # Create the local file ~/.aws/credentials # - ############################################ - CREATE_CREDS_CMD=$(echo -e "[default]\naws_access_key_id=$AWS_ACCESS_KEY_ID\naws_secret_access_key=$AWS_SECRET_ACCESS_KEY" >> $LOCAL_CRED_FILE ) - - ####################### - # Load the error code # - ####################### - ERROR_CODE=$? - - ############################## - # Check the shell for errors # - ############################## - if [ $ERROR_CODE -ne 0 ]; then - echo "ERROR! Failed to create file:[$LOCAL_CRED_FILE]!" - echo "ERROR:[$CREATE_CREDS_CMD]" - ################################################### - # Set the ERROR_FOUND flag to 1 to drop out build # - ################################################### - ERROR_FOUND=1 - ERROR_CAUSE="Failed to create file:[$LOCAL_CRED_FILE]!" - else - echo "Successfully created:[$LOCAL_CRED_FILE]" - fi - ####################################### # Create the local file ~/.aws/config # ####################################### @@ -539,7 +516,7 @@ CreateCheck() ########################################## # Call to Github to create the Check API # ########################################## - CREATE_CHECK_CMD=$( curl -sk -X POST \ + CREATE_CHECK_CMD=$( curl -k --fail -X POST \ --url "$GITHUB_URL/repos/$GITHUB_ORG/$GITHUB_REPO/check-runs" \ -H 'accept: application/vnd.github.antiope-preview+json' \ -H "authorization: Bearer $GITHUB_TOKEN" \ @@ -591,20 +568,29 @@ RunDeploy() # - Package SAM template # - Deploy packaged SAM template - ################# - # Build the App # - ################# - BuidApp + # Go into loop if no errors detected + if [ $ERROR_FOUND -eq 0 ]; then + ################# + # Build the App # + ################# + BuidApp + fi - ######################## - # Package the template # - ######################## - PackageTemplate + # Go into loop if no errors detected + if [ $ERROR_FOUND -eq 0 ]; then + ######################## + # Package the template # + ######################## + PackageTemplate + fi - ####################### - # Deploy the template # - ####################### - DeployTemplate + # Go into loop if no errors detected + if [ $ERROR_FOUND -eq 0 ]; then + ####################### + # Deploy the template # + ####################### + DeployTemplate + fi } ################################################################################ #### Function BuidApp ########################################################## @@ -753,6 +739,12 @@ DeployTemplate() #### Function ValidateSourceAndRuntime ######################################### ValidateSourceAndRuntime() { + ########## + # Prints # + ########## + echo "--------------------------------------------" + echo "Validating file:[$AWS_SAM_TEMPLATE] and NodeJS runtime..." + ############################################## # Validate the user has the template.yml and # # we have the correct runtime set # @@ -798,6 +790,7 @@ ValidateSourceAndRuntime() ERROR_FOUND=1 ERROR_CAUSE="Failed to find [Runtime] in:[$GITHUB_WORKSPACE/$AWS_SAM_TEMPLATE]!" else + echo "File found and Runtime variable parsed successfully" ########################### # Need to set the runtime # ########################### @@ -808,7 +801,7 @@ ValidateSourceAndRuntime() ################################################## # Need to set the Runtime for the app deployment # ################################################## - SetRuntime "$RUNTIME" + #SetRuntime "$RUNTIME" } ################################################################################ #### Function SetRuntime ####################################################### @@ -819,6 +812,12 @@ SetRuntime() ################ RUNTIME=$1 + ########## + # Prints # + ########## + echo "--------------------------------------------" + echo "Setting NodeJS runtime..." + ########################################### # Remove the 'NodeJS' and get the version # ########################################### @@ -899,7 +898,7 @@ UpdateCheck() ########################### # Build the finished time # ########################### - FINISHED_DATE=$(date --utc "+%FT%T.%N" | sed -r 's/[[:digit:]]{7}$/Z/') + FINISHED_DATE=$(date +"%Y-%m-%dT%H:%M:%SZ") ###################################################### # Set the conclusion to failure if errors were found # @@ -914,7 +913,7 @@ UpdateCheck() ########################################## # Call to Github to update the Check API # ########################################## - UPDATE_CHECK_CMD=$( curl -sk -X PATCH \ + UPDATE_CHECK_CMD=$( curl -k --fail -X PATCH \ --url "$GITHUB_URL/repos/$GITHUB_ORG/$GITHUB_REPO/check-runs/$CHECK_ID" \ -H 'accept: application/vnd.github.antiope-preview+json' \ -H "authorization: Bearer $GITHUB_TOKEN" \ @@ -935,13 +934,22 @@ UpdateCheck() exit 1 else echo "Success! Updated Github Checks API" - exit 0 fi } ################################################################################ ################################# MAIN ######################################### ################################################################################ +####################### +# Debug print all env # +####################### +if [ $DEBUG -ne 0 ]; then + echo "--------------------------------------------" + echo "PRINTENV" + printenv + echo "--------------------------------------------" +fi + # Go into loop if no errors detected if [ $ERROR_FOUND -eq 0 ]; then ####################### @@ -993,7 +1001,8 @@ ValidateSourceAndRuntime # Create the check in GitHub to let the # user know we are running the deploy action # We always want to inform user of the process -CreateCheck +# Note: No need to create check as were calling from inside a gitHub Action +#CreateCheck # Go into loop if no errors detected if [ $ERROR_FOUND -eq 0 ]; then @@ -1011,4 +1020,16 @@ fi # Update the check with the status # of the deployment # We always want to inform user of the process -UpdateCheck +# Note: No need to create check as were calling from inside a gitHub Action +#UpdateCheck + +############################### +# Exit with proper error code # +############################### +if [ $ERROR_FOUND -eq 0 ]; then + # Exit with SUCCESS + exit 0 +else + # Exit with ERROR + exit 1 +fi