I have a python workflow where I need to encrypt a file using GPG encryption keys – this will run in ECS using a Docker image.
Since GnuPG works on the basis of a “home directory”, I need to be able to install the gnupg executable in the container and have my script point to it, as such:
gpg = gnupg.GPG(gnupghome='/path/to/home/directory')
This is where I’m stuck.
My docker image is defined as such:
RUN apt-get update && apt-get install -y gnupg
RUN mkdir -p /opt/prefect/.gnupg && chmod 700 /opt/prefect/.gnupg
RUN python -m pip install --upgrade pip
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
Where I create a directory to store the gnupg executable – so to create an instance of GPG I would do something like…
gpg = gnupg.GPG(gnupghome='/opt/prefect/')
but this returns this error:
Unable to run gpg (gpg) - it may not be available.
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/gnupg.py", line 1094, in __init__
p = self._open_subprocess(['--list-config', '--with-colons'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/gnupg.py", line 1164, in _open_subprocess
result = Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=si, env=self.env)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.11/subprocess.py", line 1955, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'gpg'
I then tried running which gpg
in my container and it revealed this path…
/usr/bin/gpg
So I tried this…
gpg = gnupg.GPG(gnupghome='/usr/bin/')
and got the same error.
At this point I’m not sure how to proceed – any help appreciated, thanks!
Jean Paul Azzopardi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.