hashicorp / setup-packer

Run HashiCorp Packer as part of your GitHub Actions Workflow
https://github.com/marketplace/actions/setup-hashicorp-packer
Apache License 2.0
139 stars 83 forks source link

session-manager-plugin support #48

Closed 123BLiN closed 1 year ago

123BLiN commented 2 years ago

Expected Behavior

Be useful for AWS packer builds

Current Behavior

Not useful - forked

Dockerfile that works in my case:

FROM ubuntu:latest

RUN set -e;  \
    apt-get update && apt-get install -y curl apt-transport-https ca-certificates gnupg; \
    echo "deb [arch=amd64] https://apt.releases.hashicorp.com $(. /etc/lsb-release; echo "$DISTRIB_CODENAME") main" > /etc/apt/sources.list.d/hashicorp.list; \
    curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add -; \
    apt-get update -o Dir::Etc::sourcelist=sources.list.d/hashicorp.list -o Dir::Etc::sourceparts=- -o APT::Get::List-Cleanup=0; \
    apt-get install -y packer; \
    curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" -o /tmp/session-manager-plugin.deb; \
    dpkg -i /tmp/session-manager-plugin.deb; \
    apt-get autoremove -y curl apt-transport-https ca-certificates gnupg; \
    apt-get clean

COPY "entrypoint.sh" "/entrypoint.sh"

ENTRYPOINT ["/entrypoint.sh"]

Maybe it can be useful to allow to specify dockerfile content and override default one?

Steps to Reproduce

Try to build AMI in AWS with SSM session

Environment

AWS account with SSM session for connections

IdanYaffe commented 2 years ago

I also have a feeling the session manager plugin isn't working properly using this action. Getting the following error when packer trying to connect to an EC2 instance via SSM: "session-manager-plugin": executable file not found in $PATH

I didn't manage to workaround it by installing the AWS SSM plugin on the GH runner as part of another step within the same GH workflow job.

123BLiN commented 2 years ago

I think the only option may be to add it to the docker file like this https://github.com/aws/session-manager-plugin/issues/12#issuecomment-972880203 - trying to evaluate it, or switch from packer:light to other docker, like ubuntu based but it seems this is not desired based on https://github.com/hashicorp/docker-hub-images/issues/100

If the trick with docker RUN on alpine will work I will try to add a PR that will allow such steps, if not - only fork locally and adjust for your needs, also one more customisation I can think of is ~packer init support~ it is supported actually

123BLiN commented 2 years ago

This worked for my case - but only in fork of this repo, as I'm changing the base Docker image https://github.com/skeggse/docker-packer-ssm/blob/main/Dockerfile

ksatirli commented 1 year ago

Thank you for reporting this @123BLiN.

In the legacy version of this Action, this wasn't supported. You should be able to use SSM (and similar tooling) with the latest version of this Action.

See #63

psipher commented 1 year ago

Got the same error Getting the following error when packer trying to connect to an EC2 instance via SSM: "session-manager-plugin": executable file not found in $PATH , while trying to use github actions. Previously had a stage defined for installing session mananger . At the end I added RUN wget https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb && dpkg -i session-manager-plugin.deb && rm session-manager-plugin.deb in my docker file and it worked.