dockerjenkinsdockerfiledevopsakamai

command is working fine inside the docker container but not working in dockerfile when building image


dockerfile code

 FROM ubuntu:20.04
 RUN  wget https://dl.google.com/go/go1.21.0.linux-amd64.tar.gz && \
      tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz && \
      export PATH=$PATH:/usr/local/go/bin && \
      go version
 COPY akamai-v1.5.6-linux386 .
 RUN  chmod +x akamai-v1.5.6-linux386 && \
      mv akamai-v1.5.6-linux386 /usr/local/bin/akamai && \
      apt-get update
 RUN apt-get update && akamai install purge -y 
 EXPOSE 22
 CMD ["/usr/sbin/sshd", "-D"]

i am installing the akamai cli and akamai purge package. i am getting following error-

=> ERROR [9/9] RUN apt-get update && akamai install purge -y                                                                                   85.0s
------                                                                                                                                                
 > [9/9] RUN apt-get update && akamai install purge -y:                                                                                               
0.655 Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease                                                                                
0.865 Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease                                                                                          
1.133 Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]                                                                         
2.375 Hit:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease                                                                                
2.530 Fetched 114 kB in 2s (51.0 kB/s)
2.530 Reading package lists...
84.86  ERROR[0081] Package Is Not Available. Supported Packages Can Be Found Here: Https://Techdocs.Akamai.Com/Home/Page/Products-Tools-A-Z command=install
84.86  ERROR[0081] INSTALL ERROR: Package is not available. Supported packages can be found here: https://techdocs.akamai.com/home/page/products-tools-a-z command=install
84.86 Package is not available. Supported packages can be found here: https://techdocs.akamai.com/home/page/products-tools-a-z
------
Dockerfile:163

 161 |     # ENV PATH=/usr/local/bin/akamai:$PATH
 162 |     # RUN echo $PATH
 163 | >>> RUN apt-get update && akamai install purge -y 
 164 |     
 165 |     EXPOSE 22

ERROR: failed to solve: process "/bin/sh -c apt-get update && akamai install purge -y" did not complete successfully: exit code: 1

i am getting error on akamai install purge command. But same command is working if i comment it in dockerfile and use inside the container. error is showing that package is not available but when i checked package is available at given link


Solution

  • Looks like you want to have akamai purge running on an Ubuntu Docker image.

    ๐Ÿ—Ž Dockerfile

    FROM golang:alpine3.17 as builder
    
    RUN apk add --no-cache $(apk search --no-cache | grep -q ^upx && echo -n upx) git \
      && git clone --depth=1 https://github.com/akamai/cli-purge \
      && cd cli-purge \
      && go mod tidy \
      && go build -o /akamai-purge -ldflags="-s -w" \
      && upx -3 -o/akamai-purge.upx /akamai-purge
    
    RUN apk add --no-cache $(apk search --no-cache | grep -q ^upx && echo -n upx) git \
      && git clone --depth=1 https://github.com/akamai/cli \
      && cd cli \
      && go mod tidy \
      && go build -o /akamai -ldflags="-s -w" cli/main.go \
      && upx -3 -o/akamai.upx /akamai 
    
    FROM ubuntu:20.04
    
    ENV AKAMAI_CLI_HOME=/cli
    
    RUN mkdir -p \
            $AKAMAI_CLI_HOME/.akamai-cli/src/cli-purge/bin \
            $AKAMAI_CLI_HOME/.akamai-cli/logs
        
    COPY --from=builder /akamai-purge.upx $AKAMAI_CLI_HOME/.akamai-cli/src/cli-purge/bin/akamai-purge
    COPY --from=builder /go/cli-purge/cli.json $AKAMAI_CLI_HOME/.akamai-cli/src/cli-purge/cli.json
    
    COPY --from=builder /akamai.upx /bin/akamai
    
    COPY config $AKAMAI_CLI_HOME/.akamai-cli/config 
    
    RUN chmod -R a+rwx ${AKAMAI_CLI_HOME}
    

    Adding a configuration file will prevent you from being prompted about automatic upgrades when you first run akamai. This is copied across in the second stage of the build.

    ๐Ÿ—Ž config

    [cli]
    cache-path         = /cli/.akamai-cli/cache
    config-version     = 1.1
    last-upgrade-check = ignore
    

    enter image description here