Compare commits

...

18 Commits

Author SHA1 Message Date
hashicorp-copywrite[bot]
8c999b2ff7 [COMPLIANCE] Update Apache-2.0 LICENSE (#66)
Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2022-12-07 13:05:00 -08:00
Warren Krewenki
39e578e79f Update dockerfile to use packer 1.8.4 (#62)
Update the base Dockerfile to pull in the latest packer:light instead of the old version currently used by this action.
2022-12-06 19:34:32 +01:00
Guillaume Winter
da1fc3d139 Update to packer 1.8.2 (#46)
* Update to packer 1.8.2

* Update to packer 1.8.2
2022-08-18 11:59:40 +02:00
Amar Lojo
85839311bf adds docs for HCP support (#40) 2022-04-13 14:24:30 +02:00
Alan Ning
591a97b495 Added doc to describe the working_directory field (#39) 2022-04-13 13:51:18 +02:00
William
ca6f8f3f18 Add working_directory to documentation (#26) 2022-04-13 13:48:49 +02:00
Amar Lojo
501495b3a3 HCP Client ID & Secret updated (#34)
changed syntax
2022-04-06 09:53:53 +02:00
Kuldeep Rishi
4a58ae79e4 Update to Packer 1.7.8 (#29) 2021-12-13 15:36:10 +01:00
Sylvia Moss
93da82af22 update changelog (#18) 2021-03-02 09:58:19 +01:00
Sylvia Moss
f3ef35b95e Document detailed logs and upgrade image to Packer v1.7.0 (#17)
* add docs for detailed logs

* update packer image to v1.7.0

* fix table format

* fix table and make target not required

* document target as directory

* make default target the working dir

* fix readme

* add init command to the list

* removes extraneous spaces

Co-authored-by: Kerim Satirli <k.satirli@gmail.com>
2021-02-27 06:38:18 -05:00
Kerim Satirli
552c468107 documentation updates (#15)
* updates links and documentation for new GH Org
2021-02-25 16:37:27 +01:00
Kerim Satirli
5338887b31 updates to Packer 1.6.6 (#13)
* updates to Packer 1.6.6
2021-01-22 19:08:56 +01:00
Tom Parker-Shemilt
74ff345c9a Add support for working_directory (#11) 2021-01-22 19:07:02 +01:00
Jason
9cd0219a3b update Dockerfile and Readme to packer 6.2 (#8)
* update Dockerfile and Readme to packer 1.6.2

* update README to pass quality check
2021-01-22 18:09:04 +01:00
Frank J. Lamantia
71e9f608bf Updates to fail if templates do not pass validation (#4) 2020-06-18 09:56:00 +02:00
Aaron Tesch
ebc43821c4 ISSUE 6 - Fixed usage section in README.md (#7)
Co-authored-by: Aaron Tesch <darc_wing@hotmail.com>
2020-06-18 09:55:39 +02:00
FrankTheTank
b4a8c1ee67 update uses line (#3) 2020-03-30 12:12:23 +02:00
Kerim Satirli
5236a2b53a updates Packer to 1.5.5 (#2)
* updates Packer to `1.5.5`
2020-03-27 11:31:18 +01:00
6 changed files with 87 additions and 29 deletions

View File

@@ -1,4 +1,11 @@
# `0.2.0` (2020-03-25)
# `0.3.0` (UNRELEASED, 2022-08)
* Update Dockerfile to point to packer version `1.8.2`
* Change `target` default to `.` [#17](https://github.com/hashicorp/packer-github-actions/pull/17)
* Mark `target` as not required [#17](https://github.com/hashicorp/packer-github-actions/pull/17)
* Add support for working_directory [#11](https://github.com/operatehappy/packer-github-actions/pull/11)
## `0.2.0` (2020-03-25)
* Adds Packer action (#1) ([d80192d](https://github.com/ksatirli/packer-github-actions/commit/d80192d)), closes [#1](https://github.com/ksatirli/packer-github-actions/issues/1)
* adds GitHub Actions for `code-quality` and `repository-management` ([2a0399e](https://github.com/ksatirli/packer-github-actions/commit/2a0399e))
@@ -6,4 +13,3 @@
## `0.1.0` (2020-03-24)
* adds base files ([6f7428a](https://github.com/ksatirli/packer-github-actions/commit/6f7428a))

View File

@@ -1,4 +1,5 @@
FROM hashicorp/packer:light@sha256:df7feeff930b04a42f2027dd0924392246f7b5a38f0c56531a2d14cd0d1e9408
# see https://hub.docker.com/r/hashicorp/packer/tags for all available tags
FROM hashicorp/packer:light@sha256:dd9868ae2b4d4fc658ed32ab9f3277b0a85ad266f8880351f2d51de038e4db5c
COPY "entrypoint.sh" "/entrypoint.sh"

View File

@@ -1,3 +1,5 @@
Copyright (c) 2020 HashiCorp, Inc.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

View File

@@ -1,6 +1,6 @@
# GitHub Action: Packer
> GitHub Action for running Packer [commands](https://packer.io/docs/commands/index.html).
> GitHub Action for running Packer [commands](https://www.packer.io/docs/commands).
## Table of Contents
@@ -8,16 +8,18 @@
- [Table of Contents](#table-of-contents)
- [Usage](#usage)
- [Inputs](#inputs)
- [command](#command)
- [arguments](#arguments)
- [target](#target)
- [`command`](#command)
- [`arguments`](#arguments)
- [`target`](#target)
- [`working_directory`](#working_directory)
- [Detailed logs](#detailed-logs)
- [Notes](#notes)
- [Author Information](#author-information)
- [License](#license)
## Usage
Add the Action to your [GitHub Workflow](https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#creating-a-workflow-file) like so:
Add the Action to your [GitHub Workflow](https://docs.github.com/en/actions/learn-github-actions#creating-a-workflow-file) like so:
```yaml
---
@@ -38,43 +40,51 @@ jobs:
# fix backwards incompatibilities in template
- name: Fix Template
uses: operatehappy/packer-github-action
uses: hashicorp/packer-github-actions@master
with:
command: fix
# validate templates
- name: Validate Template
uses: operatehappy/packer-github-action
uses: hashicorp/packer-github-actions@master
with:
command: validate
arguments: -syntax-only
target: artifacts.pkr.json packer.json
target: packer.pkr.hcl
# build artifact
- name: Build Artifact
uses: operatehappy/packer-github-action
uses: hashicorp/packer-github-actions@master
with:
command: build
arguments: "-color=false -on-error=abort"
target: packer.pkr.hcl
working_directory: infrastructure/packer
env:
PACKER_LOG: 1
HCP_CLIENT_ID: ${{ secrets.HCP_CLIENT_ID }}
HCP_CLIENT_SECRET: ${{ secrets.HCP_CLIENT_SECRET }}
# additional steps to process artifacts
```
### Inputs
| Name | Description | Required | Default |
|-------------|-----------------------|----------|----------------------|
| `command` | command to execute | yes | |
| `arguments` | arguments for command | no | |
| `target` | file(s) to target | yes | `artifacts.pkr.json` |
| Name | Description | Required | Default |
|---------------------|--------------------------------|----------|---------|
| `command` | command to execute | yes | |
| `arguments` | arguments for command | no | |
| `target` | file(s) or directory to target | no | `.` |
| `working_directory` | working directory for command | no | `.` |
#### `command`
`command` supports the following subset of Packer [CLI commands](https://packer.io/docs/commands/index.html):
- [build](https://packer.io/docs/commands/build.html) to generate a set of artifacts from a template
- [fix](https://packer.io/docs/commands/fix.html) to find and correct backwards incompatible stanzas in a template
- [validate](https://packer.io/docs/commands/validate.html) to validate the syntax and configuration of a template
- [init](https://www.packer.io/docs/commands/init) to download Packer plugin binaries
- [build](https://www.packer.io/docs/commands/build) to generate a set of artifacts from a template
- [fix](https://www.packer.io/docs/commands/fix) to find and correct backwards incompatible stanzas in a template
- [validate](https://www.packer.io/docs/commands/validate) to validate the syntax and configuration of a template
Other CLI commands (`console`, `inspect` and `version`) are _technically_ supported, but have limited utility in a GitHub Actions Workflow, due to their interactive nature.
@@ -82,29 +92,58 @@ Other CLI commands (`console`, `inspect` and `version`) are _technically_ suppor
`arguments` supports all options available for the respective `command`.
The arguments must be provided as a single string. Multiple arguments should be concatenated like so: "-color=false -on-error=abort"
The arguments must be provided as a single string. Multiple arguments should be concatenated like so: `-color=false -on-error=abort`
#### `target`
`target` supports a string consisting of one or more file paths:
`target` supports a string consisting of one or more file or directory paths:
```yaml
# single file
target: artifacts.pkr.json
target: artifacts.pkr.hcl
# multiple files, separated by whitespace
target: artifacts.pkr.json packer.json
target: artifacts.pkr.hcl packer.pkr.hcl
# working directory
target: .
```
The Action will iterate over each file and run each `command`, separately.
#### `working_directory`
`working_directory` supports a string consisting of a directory path. This should be a relative path in your repository where you want the packer command to run.
## Detailed logs
Packer has an option to enable more detailed logs by setting the `PACKER_LOG` environment variable.
Any value other than `""` (empty string) and `"0"`, will cause detailed logs to appear on stderr.
To set `PACKER_LOG=1`, simply define the environment variable in the step configuration like:
```yaml
# build artifact
- name: Build Artifact
uses: hashicorp/packer-github-actions@master
with:
command: build
arguments: "-color=false -on-error=abort"
target: packer.pkr.hcl
env:
PACKER_LOG: 1
```
## Notes
- To enable debug logging, create a secret named `ACTIONS_STEP_DEBUG` with the value `true`. See [here](https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-debug-message) for more information.
- To enable debug logging, create a secret named `ACTIONS_STEP_DEBUG` with the value `true`. See [here](https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-debug-message) for more information.
- If you want to use HCP Packer as central image repository, do not forget to add HCP Secrets under your repo settings. See [here](https://github.com/Azure/actions-workflow-samples/blob/master/assets/create-secrets-for-GitHub-workflows.md)
- When using [HCP Packer Registry](https://cloud.hashicorp.com/docs/packer), you will need to set `HCP_CLIENT_ID` and `HCP_CLIENT_SECRET` environment variables to your job steps. See [Service Principals](https://cloud.hashicorp.com/docs/hcp/access-control/service-principals) guide for how you can generate these credentials, and [Encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) guide for how you can configure and reference secrets in your Actions.
## Author Information
This module is maintained by the contributors listed on [GitHub](https://github.com/operatehappy/packer-github-action/graphs/contributors).
This module is maintained by the contributors listed on [GitHub](https://github.com/hashicorp/packer-github-actions/graphs/contributors).
Development of this module was sponsored by [Operate Happy](https://github.com/operatehappy).

View File

@@ -10,10 +10,14 @@ inputs:
required: true
arguments:
description: arguments for command
required: false
working_directory:
description: working directory for command (defaults to root)
required: false
target:
description: file(s) to target
required: true
default: artifacts.pkr.json
description: file(s) or directory to target
required: false
default: .
outputs:
command:

View File

@@ -1,11 +1,17 @@
#!/usr/bin/env bash
set -e
# fail if INPUT_COMMAND is not set
if [ -z "${INPUT_COMMAND}" ]; then
echo "Required variable \`command\` is missing"
exit 1
fi
if [ -n "${INPUT_WORKING_DIRECTORY}" ]; then
cd "${INPUT_WORKING_DIRECTORY}"
fi
# assemble operation
if [ -z "${INPUT_ARGUMENTS}" ]; then
OPERATION="packer ${INPUT_COMMAND}"