Skip to content

Commit

Permalink
Refactoring Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
madelen-at-work committed Apr 15, 2024
1 parent 82d675a commit 9fff705
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
dockerfile: Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: ACAPARCH=${{ matrix.arch }}
build-args: ARCH=${{ matrix.arch }}
outputs: "type=local,dest=build"
- name: Get name of EAP-file
id: get_eap_file_name
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build*/
tls/
tmp/
dockerd
docker-proxy
Expand Down
49 changes: 32 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# syntax=docker/dockerfile:1

ARG DOCKER_IMAGE_VERSION=26.0.0
ARG PROCPS_VERSION=v3.3.17

ARG REPO=axisecp
ARG ACAPARCH=armv7hf
ARG ARCH=armv7hf

ARG VERSION=1.13
ARG UBUNTU_VERSION=22.04
ARG NATIVE_SDK=acap-native-sdk

FROM ${REPO}/${NATIVE_SDK}:${VERSION}-${ACAPARCH}-ubuntu${UBUNTU_VERSION} as build_image
FROM ${REPO}/${NATIVE_SDK}:${VERSION}-${ARCH}-ubuntu${UBUNTU_VERSION} AS sdk_image

FROM build_image AS ps
ARG PROCPS_VERSION=v3.3.17
ARG BUILD_DIR=/build
ARG EXPORT_DIR=/export
FROM sdk_image AS build_image

# hadolint ignore=DL3009
RUN <<EOF
apt-get update
apt-get -q install -y -f --no-install-recommends \
Expand All @@ -27,12 +26,21 @@ RUN <<EOF
ln -s /usr/bin/libtoolize /usr/bin/libtool
EOF

FROM build_image AS ps

ARG PROCPS_VERSION
ARG BUILD_DIR=/build
ARG EXPORT_DIR=/export

WORKDIR $BUILD_DIR
RUN git clone --depth 1 -b $PROCPS_VERSION 'https://gitlab.com/procps-ng/procps' .

ARG BUILD_CACHE=build.cache
RUN echo ac_cv_func_realloc_0_nonnull=yes >$BUILD_CACHE \
&& echo ac_cv_func_malloc_0_nonnull=yes >>$BUILD_CACHE
RUN <<EOF
echo ac_cv_func_realloc_0_nonnull=yes >$BUILD_CACHE
echo ac_cv_func_malloc_0_nonnull=yes >>$BUILD_CACHE
EOF

RUN <<EOF
. /opt/axis/acapsdk/environment-setup*
./autogen.sh
Expand All @@ -47,21 +55,18 @@ EOF
WORKDIR $EXPORT_DIR
RUN cp $BUILD_DIR/ps/pscommand ps

FROM build_image as build
FROM sdk_image AS docker-binaries

ARG DOCKER_IMAGE_VERSION
ENV DOCKERVERSION ${DOCKER_IMAGE_VERSION}
ARG ACAPARCH
ENV ARCH ${ACAPARCH}
WORKDIR /download

COPY app /opt/app
COPY --from=ps /export/ps /opt/app
ARG ARCH
ARG DOCKER_IMAGE_VERSION

# Download and extract dockerd and its dependencies
RUN <<EOF
if [ "$ACAPARCH" = "armv7hf" ]; then
if [ "$ARCH" = "armv7hf" ]; then
export DOCKER_ARCH="armhf";
elif [ "$ACAPARCH" = "aarch64" ]; then
elif [ "$ARCH" = "aarch64" ]; then
export DOCKER_ARCH="aarch64";
fi;
curl -Lo docker_binaries.tgz "https://download.docker.com/linux/static/stable/${DOCKER_ARCH}/docker-${DOCKER_IMAGE_VERSION}.tgz" ;
Expand All @@ -70,7 +75,17 @@ RUN <<EOF
tar -xz -f docker_binaries.tgz --strip-components=1 docker/docker-proxy ;
EOF

FROM sdk_image AS build

WORKDIR /opt/app

COPY app .
COPY --from=ps /export/ps .
COPY --from=docker-binaries \
/download/dockerd \
/download/docker-init \
/download/docker-proxy ./

RUN <<EOF
. /opt/axis/acapsdk/environment-setup*
acap-build . \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ To build the Docker ACAP use docker buildx with the provided Dockerfile:

```sh
# Build Docker ACAP image
docker buildx build --file Dockerfile --tag docker-acap:<ARCH> --build-arg ACAPARCH=<ARCH> --output <build-folder> .
docker buildx build --file Dockerfile --tag docker-acap:<ARCH> --build-arg ARCH=<ARCH> --output <build-folder> .
```

where `<ARCH>` is either `armv7hf` or `aarch64`. `<build-folder>` is the path to an output folder
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ done

# Build and copy out the acap
# shellcheck disable=SC2086
docker buildx build --build-arg ACAPARCH="$arch" \
docker buildx build --build-arg ARCH="$arch" \
--build-arg HTTP_PROXY="${HTTP_PROXY:-}" \
--build-arg HTTPS_PROXY="${HTTPS_PROXY:-}" \
--file Dockerfile \
Expand Down

0 comments on commit 9fff705

Please sign in to comment.