-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dawitnida/feature/Dockerfile
Include Dockerfile for packer validate action.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |