Skip to content

Commit

Permalink
Fast exit when there is an error in Docker building
Browse files Browse the repository at this point in the history
  • Loading branch information
Cacsjep committed Feb 2, 2025
1 parent 72773ff commit 7e7e275
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 24 deletions.
11 changes: 7 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ COPY . ${APP_DIR}
WORKDIR ${APP_DIR}
RUN python generate_makefile.py ${APP_NAME} ${GO_APP} ${APP_MANIFEST}
WORKDIR ${APP_DIR}/${GO_APP}
RUN . /opt/axis/acapsdk/environment-setup* && \
acap-build . ${ACAP_FILES} && \
if [ "${INSTALL}" = "YES" ]; then eap-install.sh ${IP_ADDR} ${PASSWORD} install; fi && \
if [ "${START}" = "YES" ]; then eap-install.sh start; fi
RUN . /opt/axis/acapsdk/environment-setup* && acap-build . ${ACAP_FILES} || (echo "acap-build error" && exit 1)

# Install ACAP only if INSTALL=YES
RUN . /opt/axis/acapsdk/environment-setup* && if [ "$INSTALL" = "YES" ]; then eap-install.sh ${IP_ADDR} ${PASSWORD} install || (echo "acap-build error install" && exit 1); fi

# Start ACAP only if START=YES
RUN . /opt/axis/acapsdk/environment-setup* && if [ "$START" = "YES" ]; then eap-install.sh start || (echo "acap-build error start" && exit 1); fi

#-------------------------------------------------------------------------------
# Create output directory, we copy files from eap to host
Expand Down
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Its main purpose is to build apps with [goxis](https://github.com/Cacsjep/goxis)
go install github.com/Cacsjep/goxisbuilder@latest
```

> [!NOTE]
> MAC OS: If you not already have **go bin directory** in your path you need to perform `export PATH=$PATH:$HOME/go/bin`
### Quick Start (New Project)
Creating a new project is very handy, it creates an application directory with all the necessary stuff inside. :)
```shell
Expand Down
12 changes: 12 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
B: Bug
I: Improvment
F: Feature
D: Docs

Known Issues/Limitations:
x) Watch mode only work with digest authentication

TAG v1.2.2:
I: Fast exit when there is an error in Docker building
I: Add new manifest and sdk versions
D: Add MACOS path info in readme.
9 changes: 6 additions & 3 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func dockerBuild(ctx context.Context, cli *client.Client, bc *BuildConfiguration

buildResponse, err := cli.ImageBuild(ctx, buildContext, options)
if err != nil {
return fmt.Errorf("failed to build image: %w", err)
return fmt.Errorf("unable to build image: %w", err)
}
defer buildResponse.Body.Close()
decoder := json.NewDecoder(buildResponse.Body)
Expand All @@ -115,15 +115,18 @@ func dockerBuild(ctx context.Context, cli *client.Client, bc *BuildConfiguration
if err := decoder.Decode(&m); err == io.EOF {
break
} else if err != nil {
return fmt.Errorf("failed to decode build response: %s", err.Error())
return fmt.Errorf("unable to decode build response: %s", err.Error())
}

s, ok := m["stream"]
if ok {
// exit when we see the acap-build error message but when it is not a step, eg command line in dockerfile
if strings.Contains(s.(string), "acap-build error") && !strings.Contains(s.(string), "Step") {
return errors.New(s.(string))
}
fmt.Print(s)
}
}

return nil
}

Expand Down
41 changes: 24 additions & 17 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func configureSdk(lowestSdkVersion bool, buildConfig *BuildConfiguration) {

func watchPackageLog(buildConfig *BuildConfiguration) {
// Setup a channel to listen for interrupt signal (Ctrl+C)
sigChan := make(chan os.Signal, 1)
sigChan := make(chan os.Signal, 2)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)

ticker := time.NewTicker(3 * time.Second)
Expand Down Expand Up @@ -190,22 +190,25 @@ func printCompatibility(buildConfig *BuildConfiguration) {

// Maps for Native SDK version to Firmware compatibility
nativeSdkToFirmware := map[string]string{
"1.0": "10.7 and later until LTS",
"1.1": "10.9 and later until LTS",
"1.2": "10.10 and later until LTS",
"1.3": "10.12 (LTS)",
"1.4": "11.0 and later until LTS",
"1.5": "11.1 and later until LTS",
"1.6": "11.2 and later until LTS",
"1.7": "11.3 and later until LTS",
"1.8": "11.4 and later until LTS",
"1.9": "11.5 and later until LTS",
"1.10": "11.6 and later until LTS",
"1.11": "11.7 and later until LTS",
"1.12": "11.8 and later until LTS",
"1.13": "11.9 and later until LTS",
"1.14": "11.10 and later until LTS",
"1.15": "11.11 (LTS)",
"1.0": "10.7 and later until LTS",
"1.1": "10.9 and later until LTS",
"1.2": "10.10 and later until LTS",
"1.3": "10.12 (LTS)",
"1.4": "11.0 and later until LTS",
"1.5": "11.1 and later until LTS",
"1.6": "11.2 and later until LTS",
"1.7": "11.3 and later until LTS",
"1.8": "11.4 and later until LTS",
"1.9": "11.5 and later until LTS",
"1.10": "11.6 and later until LTS",
"1.11": "11.7 and later until LTS",
"1.12": "11.8 and later until LTS",
"1.13": "11.9 and later until LTS",
"1.14": "11.10 and later until LTS",
"1.15": "11.11 (LTS)",
"12.0.0": "12.0 and later until LTS",
"12.1.0": "12.1 and later until LTS",
"12.2.0": "12.2 and later until LTS",
}

// Check if it's using the native SDK or standard SDK
Expand Down Expand Up @@ -234,6 +237,10 @@ func printCompatibility(buildConfig *BuildConfiguration) {
"1.4.0": "11.7",
"1.5.0": "11.8",
"1.6.0": "11.9",
"1.7.0": "11.10",
"1.7.1": "12.0",
"1.7.2": "12.1",
"1.7.3": "12.2",
}

if firmware, ok := schemaToFirmware[buildConfig.Manifest.SchemaVersion]; ok {
Expand Down

0 comments on commit 7e7e275

Please sign in to comment.