Skip to content

Commit

Permalink
fix(docker): use target binary build param as name of image entrypoint (
Browse files Browse the repository at this point in the history
#1573)

## Summary
Fixes container images to use the `$TARGETBINARY` build param as the
name of the binary run in the image entrypoint.

## Background
Before this patch, the containerfile entrypoint used a symlinked
`/usr/local/bin/entrypoint` as the entrypoint, which caused the name of
the binary to be `"entrypoint"`. This itself was to workaround to the
`ENTRYPOINT` command not allowing for variables in exec form. This patch
instead creates an ad-hoc script which itself executes `$TARGETBINARY`,
and uses this script as the entrypoint.

Together with the script using `exec` and the exec form of `ENTRYPOINT`
the expected binary (and process) name are used.

Taking `astria-cli`'s help message as an example:

Before:
```
Get the balance of a Sequencer account

Usage: entrypoint sequencer balance get [OPTIONS] <ADDRESS>
```

After:
```
Get the balance of a Sequencer account

Usage: astria-cli sequencer balance get [OPTIONS] <ADDRESS>
```

## Changes
- Create an adhoc `/usr/local/bin/entrypoint.sh` script in
`containerfiles/Dockerfile` which is used as a new entrypoint and
executes `$TARGETBINARY`

## Testing
Built and ran images using the dockerfile. No functionality was changed
but the binary is `$TARGETBINARY` and not `entrypoint` now.

## Related Issues
closes #1571
  • Loading branch information
SuperFluffy authored Sep 30, 2024
1 parent 0877e62 commit b6df7fd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions containerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,10 @@ RUN \
apt-get clean; \
rm -rf /var/lib/apt/lists/*;
COPY --from=builder /build/release/$TARGETBINARY /usr/local/bin/$TARGETBINARY
RUN ln -s /usr/local/bin/$TARGETBINARY /usr/local/bin/entrypoint
ENTRYPOINT ["/usr/local/bin/entrypoint"]

# HACK: Ensure that $TARGETBINARY is the binary name.
ENV TARGETBINARY=$TARGETBINARY
RUN \
printf '#!/bin/sh\nexec /usr/local/bin/$TARGETBINARY $@\n' > /usr/local/bin/entrypoint.sh; \
chmod +x /usr/local/bin/entrypoint.sh;
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

0 comments on commit b6df7fd

Please sign in to comment.