Skip to content

Commit

Permalink
finishing touches
Browse files Browse the repository at this point in the history
  • Loading branch information
frantjc committed Oct 30, 2022
1 parent 5557d3c commit 0f1d093
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# dockerfile-ADDendum

> _not yet thoroughly tested_
Small script to pair with the Dockerfile `ADD` directive to make an idempotent action regardless of if the `<src>` of the `ADD` is a local tar archive or a tar archive from a remove URL.

## use case
Expand All @@ -17,10 +15,10 @@ This is where the ADDendum comes in:
## usage

```Dockerfile
ARG zip=zip_3.0_x86_64.tgz
ADD ${zip} /usr/local/bin
ARG tgz=zip_3.0_x86_64.tgz
ADD ${tgz} /tmp
COPY --from=ghcr.io/frantjc/dockerfile-addendum /addendum /usr/local/bin
RUN addendum -ruo /usr/local/bin /usr/local/bin/zip_3.0_x86_64.tgz
RUN addendum -ruo /usr/local/bin /tmp/$(basename ${tgz})
```

Now this Dockerfile can be built with `--build-arg zip=<src>` where `<src>` is either a tar archive at a remote URL or a local tar archive.
Now this Dockerfile can be built with `--build-arg tgz=<src>` where `<src>` is either a tar archive at a remote URL or a local tar archive.
5 changes: 1 addition & 4 deletions pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewRoot() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
var (
ctx = cmd.Context()
logr = addendum.LoggerFrom(ctx)
_ = addendum.LoggerFrom(ctx)
path = args[0]
ext = filepath.Ext(path)
compressed = gz || strings.EqualFold(ext, ".tgz") || strings.EqualFold(ext, ".gz") || strings.EqualFold(ext, ".tar.gz")
Expand All @@ -51,7 +51,6 @@ func NewRoot() *cobra.Command {
r io.Reader
)
if compressed {
logr.Info("uncompressing " + f.Name())
if r, err = gzip.NewReader(f); err != nil {
return err
}
Expand All @@ -68,7 +67,6 @@ func NewRoot() *cobra.Command {
switch {
case err == io.EOF:
if rm {
logr.Info("removing " + path)
if err = os.Remove(path); err != nil {
return err
}
Expand Down Expand Up @@ -116,7 +114,6 @@ func NewRoot() *cobra.Command {
if un {
if exe, err := os.Executable(); err == nil {
if exe, err = filepath.EvalSymlinks(exe); err == nil {
logr.Info("uninstalling " + exe)
return os.Remove(exe)
}

Expand Down
2 changes: 1 addition & 1 deletion testdata/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM alpine:3.15
ARG tgz=test.tgz
ADD ${tgz} /usr/local/bin/
COPY --from=ghcr.io/frantjc/dockerfile-addendum /addendum /usr/local/bin
RUN addendum -ruo /usr/local/bin /usr/local/bin/${tgz}
RUN addendum -ruo /usr/local/bin /usr/local/bin/$(basename ${tgz})

0 comments on commit 0f1d093

Please sign in to comment.