Skip to content

Commit

Permalink
Merge pull request #1 from dawitnida/feature/Dockerfile
Browse files Browse the repository at this point in the history
Include Dockerfile for packer validate action.
  • Loading branch information
dawitnida authored Apr 4, 2019
2 parents 03de574 + 37c6eb7 commit 317d3ff
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Packer template
# Cache objects
packer_cache/

# For built boxes
*.box

.idea/*

16 changes: 16 additions & 0 deletions validate/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM hashicorp/packer:1.3.5

LABEL "com.github.actions.name" = "packer-validate"
LABEL "com.github.actions.description" = "Validate packer template file in a directory"
LABEL "com.github.actions.icon" = "alert-circle"
LABEL "com.github.actions.color" = "orange"

LABEL "repository" = "https://github.com/dawitnida/packer-github-actions"
LABEL "homepage" = "https://github.com/dawitnida/packer-github-actions"
LABEL "maintainer" = "Dawit Nida <dawit@dawitnida.com>"

RUN apk --no-cache add jq

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
25 changes: 25 additions & 0 deletions validate/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
set -e

set +e
# Run packer template validator
VALIDATE_OUTPUT=$(sh -c "packer validate -no-color $*" 2>&1)
VALIDATE_SUCCESS=$?
echo "$VALIDATE_OUTPUT"
set -e

# Capture the result
if [ $VALIDATE_SUCCESS -eq 0 ]; then
exit 0
fi

# Spit out the validation output for reference
VALIDATE_COMMENT="#### \`packer validate\` Failed
\`\`\`
$VALIDATE_OUTPUT
\`\`\`"
VALIDATE_PAYLOAD=$(echo '{}' | jq --arg body "$VALIDATE_COMMENT" '.body = $body')
VALIDATE_COMMENTS_URL=$(cat /github/workflow/event.json | jq -r .pull_request.comments_url)
curl -s -S -H "Authorization: token $GITHUB_TOKEN" --header "Content-Type: application/json" --data "$VALIDATE_PAYLOAD" "$VALIDATE_COMMENTS_URL" > /dev/null

exit $VALIDATE_SUCCESS

0 comments on commit 317d3ff

Please sign in to comment.