CodeBuild skipping binary file in "file" of "artifacts" section

0

I have a buildspec.yml file like the one below -

version: 0.2
phases:
  install:
    runtime-versions:
      golang: latest
      nodejs: latest
    commands:
      - echo Installing go...
      - npm install --legacy-peer-deps
  pre_build:
    commands:
      - go mod tidy
  build:
    commands:
      - npm run prod
  post_build:
    commands:
        - cd dist && pwd && ls -al
artifacts:
  files:
    - "html/**/*"
    - "scripts/**/*"
    - "app" # <== this is binary file generated by 'go build -o dist/' command
    - "appspec.yml"
  base-direcory: "dist"
  secondary-artifacts:
    js:
      files:
        - "js/**/*"
        - "*.js"
        - "*.map"
      # discard-path: yes
      base-directory: "dist"
    css:
      files:
        - "css/**/*"
      # discard-path: yes
      base-directory: "dist"

CodeBuild is copying all mentioned file properly except the app file. It is giving the following message

[Container] 2023/12/02 16:44:52.631791 Expanding app
[Container] 2023/12/02 16:44:52.633242 Skipping invalid file path app

Here's the entire CodeBuild log file -

[Container] 2023/12/02 16:53:46.624879 Waiting for agent ping
[Container] 2023/12/02 16:53:47.625801 Waiting for DOWNLOAD_SOURCE
[Container] 2023/12/02 16:53:54.306176 Phase is DOWNLOAD_SOURCE
[Container] 2023/12/02 16:53:54.316730 CODEBUILD_SRC_DIR=/codebuild/output/src260768698/src/git-codecommit.ap-south-1.amazonaws.com/v1/repos/subrataaich.com
[Container] 2023/12/02 16:53:54.317287 YAML location is /codebuild/readonly/buildspec.yml
[Container] 2023/12/02 16:53:54.317596 Found possible syntax errors in buildspec: 
In the section artifacts
    The following keys cannot be identified:
        base-direcory
[Container] 2023/12/02 16:53:54.319617 Not setting HTTP client timeout for source type codecommit
[Container] 2023/12/02 16:53:54.319753 Processing environment variables
[Container] 2023/12/02 16:53:54.493122 Resolved 'golang' runtime alias 'latest' to '1.20'.
[Container] 2023/12/02 16:53:54.493142 Resolved 'nodejs' runtime alias 'latest' to '18'.
[Container] 2023/12/02 16:53:54.493211 Selecting 'golang' runtime version '1.20' based on manual selections...
[Container] 2023/12/02 16:53:54.493218 Selecting 'nodejs' runtime version '18' based on manual selections...
[Container] 2023/12/02 16:53:56.716236 Running command echo "Installing Go version 1.20 ..."
Installing Go version 1.20 ...

[Container] 2023/12/02 16:53:56.747918 Running command goenv global  $GOLANG_20_VERSION

[Container] 2023/12/02 16:53:57.007533 Moving to directory /codebuild/output/src260768698/src/git-codecommit.ap-south-1.amazonaws.com/v1/repos/subrataaich.com
[Container] 2023/12/02 16:53:57.008964 Unable to initialize cache download: no paths specified to be cached
[Container] 2023/12/02 16:53:57.048365 Configuring ssm agent with target id: codebuild:1833607f-f0b9-4d9a-a125-dd07accb1803
[Container] 2023/12/02 16:53:57.102923 Successfully updated ssm agent configuration
[Container] 2023/12/02 16:53:57.103309 Registering with agent
[Container] 2023/12/02 16:53:57.103324 Phases found in YAML: 4
[Container] 2023/12/02 16:53:57.103331  INSTALL: 2 commands
[Container] 2023/12/02 16:53:57.103335  PRE_BUILD: 1 commands
[Container] 2023/12/02 16:53:57.103339  BUILD: 1 commands
[Container] 2023/12/02 16:53:57.103342  POST_BUILD: 1 commands
[Container] 2023/12/02 16:53:57.103670 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] 2023/12/02 16:53:57.103697 Phase context status code:  Message: 
[Container] 2023/12/02 16:53:57.191128 Entering phase INSTALL
[Container] 2023/12/02 16:53:57.191670 Running command echo Installing go...
Installing go...

[Container] 2023/12/02 16:53:57.195717 Running command npm install --legacy-peer-deps
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'amqplib@0.5.2',
npm WARN EBADENGINE   required: { node: '>=0.8 <=9' },
npm WARN EBADENGINE   current: { node: 'v18.16.1', npm: '9.5.1' }
npm WARN EBADENGINE }
npm WARN deprecated rollup-plugin-terser@7.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
npm WARN deprecated uuid@3.3.2: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.

added 1064 packages, and audited 1065 packages in 29s

163 packages are looking for funding
  run `npm fund` for details

17 vulnerabilities (9 moderate, 7 high, 1 critical)

To address issues that do not require attention, run:
  npm audit fix

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.

[Container] 2023/12/02 16:54:39.192189 Phase complete: INSTALL State: SUCCEEDED
[Container] 2023/12/02 16:54:39.192219 Phase context status code:  Message: 
[Container] 2023/12/02 16:54:39.230356 Entering phase PRE_BUILD
[Container] 2023/12/02 16:54:39.231026 Running command go mod tidy
go: downloading go.mongodb.org/mongo-driver v1.13.0
go: downloading github.com/Masterminds/sprig/v3 v3.2.3
go: downloading github.com/go-chi/chi/v5 v5.0.10
go: downloading github.com/go-chi/cors v1.2.1
go: downloading github.com/unrolled/render v1.6.1
go: downloading github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d
go: downloading github.com/google/go-cmp v0.5.9
go: downloading github.com/Masterminds/goutils v1.1.1
go: downloading github.com/Masterminds/semver/v3 v3.2.1
go: downloading github.com/google/uuid v1.4.0
go: downloading github.com/huandu/xstrings v1.4.0
go: downloading github.com/imdario/mergo v0.3.16
go: downloading github.com/mitchellh/copystructure v1.2.0
go: downloading github.com/shopspring/decimal v1.3.1
go: downloading github.com/spf13/cast v1.5.1
go: downloading golang.org/x/crypto v0.15.0
go: downloading github.com/stretchr/testify v1.8.4
go: downloading github.com/fsnotify/fsnotify v1.7.0
go: downloading github.com/golang/snappy v0.0.1
go: downloading github.com/klauspost/compress v1.17.0
go: downloading github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe
go: downloading github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
go: downloading gopkg.in/yaml.v3 v3.0.1
go: downloading github.com/mitchellh/reflectwalk v1.0.2
go: downloading github.com/frankban/quicktest v1.14.4
go: downloading github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
go: downloading golang.org/x/sys v0.14.0
go: downloading github.com/xdg-go/scram v1.1.2
go: downloading github.com/xdg-go/stringprep v1.0.4
go: downloading golang.org/x/sync v0.3.0
go: downloading github.com/kr/pretty v0.3.1
go: downloading github.com/xdg-go/pbkdf2 v1.0.0
go: downloading golang.org/x/text v0.14.0
go: downloading github.com/kr/text v0.2.0
go: downloading github.com/rogpeppe/go-internal v1.9.0

[Container] 2023/12/02 16:54:57.562253 Phase complete: PRE_BUILD State: SUCCEEDED
[Container] 2023/12/02 16:54:57.562273 Phase context status code:  Message: 
[Container] 2023/12/02 16:54:57.595186 Entering phase BUILD
[Container] 2023/12/02 16:54:57.595888 Running command npm run prod

> subrataaich.com@1.0.0 prod
> npm run tw:prod && npm run postcss:prod && npm run vite:prod && go build -ldflags="-X 'subrataaich.com/go/server.env=prod'" -o dist/ && cp -r ./html ./scripts ./appspec.yml ./dist


> subrataaich.com@1.0.0 tw:prod
> npx tailwindcss -i ./css/main.css -o ./css/main.css --minify


Rebuilding...

Done in 469ms.

> subrataaich.com@1.0.0 postcss:prod
> postcss ./css/main.css --dir ./dist/css/ && cp ./css/manifest.json ./dist/css/


> subrataaich.com@1.0.0 vite:prod
> tsc && vite build

vite v5.0.4 building for production...
transforming...
✓ 109 modules transformed.
rendering chunks...
computing gzip size...
dist/js/registerSW.js               0.13 kB
dist/js/app.webmanifest             0.15 kB
dist/js/.vite/manifest.json         0.65 kB │ gzip:  0.23 kB
dist/js/ZwEY388w.js                 0.06 kB │ gzip:  0.08 kB │ map:   0.16 kB
dist/js/GHJCPFPl.js                 0.49 kB │ gzip:  0.26 kB │ map:   1.31 kB
dist/js/KMtMPFTT.js                 2.33 kB │ gzip:  1.20 kB │ map:   1.67 kB
dist/js/yRPCv8WQ.js               135.33 kB │ gzip: 44.28 kB │ map: 343.16 kB
dist/js/assets/index-aKFbEC9v.js  141.84 kB │ gzip: 45.46 kB │ map: 346.71 kB

PWA v0.17.2
mode      generateSW
precache  8 entries (292.63 KiB)
files generated
  dist/sw.js.map
  dist/sw.js
  dist/workbox-3e911b1d.js.map
  dist/workbox-3e911b1d.js
✓ built in 6.84s

[Container] 2023/12/02 16:55:36.398337 Phase complete: BUILD State: SUCCEEDED
[Container] 2023/12/02 16:55:36.398358 Phase context status code:  Message: 
[Container] 2023/12/02 16:55:36.427725 Entering phase POST_BUILD
[Container] 2023/12/02 16:55:36.428423 Running command cd dist && pwd && ls -al
/codebuild/output/src260768698/src/git-codecommit.ap-south-1.amazonaws.com/v1/repos/subrataaich.com/dist
total 180
drwxr-xr-x  7 root root    172 Dec  2 16:55 .
drwxr-xr-x 10 root root   4096 Dec  2 16:55 ..
-rw-r--r--  1 root root    490 Dec  2 16:55 appspec.yml
-rwxr-xr-x  2 root root     17 Dec  2 16:55 app
drwxr-xr-x  2 root root     54 Dec  2 16:55 css
drwxr-xr-x  2 root root     58 Dec  2 16:55 html
drwxr-xr-x  4 root root    245 Dec  2 16:55 js
drwxr-xr-x  2 root root     37 Dec  2 16:55 scripts
-rw-r--r--  1 root root   1399 Dec  2 16:55 sw.js
-rw-r--r--  1 root root   3772 Dec  2 16:55 sw.js.map
-rw-r--r--  1 root root  15119 Dec  2 16:55 workbox-3e911b1d.js
-rw-r--r--  1 root root 148299 Dec  2 16:55 workbox-3e911b1d.js.map
[Container] 2023/12/02 16:55:37.233024 Phase complete: POST_BUILD State: SUCCEEDED
[Container] 2023/12/02 16:55:37.233038 Phase context status code:  Message: 
[Container] 2023/12/02 16:55:37.298410 Expanding base directory path: .
[Container] 2023/12/02 16:55:37.300259 Assembling file list
[Container] 2023/12/02 16:55:37.300279 Expanding .
[Container] 2023/12/02 16:55:37.301898 Expanding file paths for base directory .
[Container] 2023/12/02 16:55:37.301909 Assembling file list
[Container] 2023/12/02 16:55:37.301913 Expanding html/**/*
[Container] 2023/12/02 16:55:37.303583 Expanding scripts/**/*
[Container] 2023/12/02 16:55:37.305120 Expanding app
[Container] 2023/12/02 16:55:37.306587 Skipping invalid file path app
[Container] 2023/12/02 16:55:37.306599 Expanding appspec.yml
[Container] 2023/12/02 16:55:37.308043 Found 6 file(s)
[Container] 2023/12/02 16:55:37.309598 Preparing to copy secondary artifacts js
[Container] 2023/12/02 16:55:37.309670 Expanding base directory path: dist
[Container] 2023/12/02 16:55:37.311098 Assembling file list
[Container] 2023/12/02 16:55:37.311112 Expanding dist
[Container] 2023/12/02 16:55:37.312538 Expanding file paths for base directory dist
[Container] 2023/12/02 16:55:37.312549 Assembling file list
[Container] 2023/12/02 16:55:37.312553 Expanding js/**/*
[Container] 2023/12/02 16:55:37.314138 Expanding *.js
[Container] 2023/12/02 16:55:37.315627 Expanding *.map
[Container] 2023/12/02 16:55:37.317082 Found 17 file(s)
[Container] 2023/12/02 16:55:37.352850 Preparing to copy secondary artifacts css
[Container] 2023/12/02 16:55:37.352869 Expanding base directory path: dist
[Container] 2023/12/02 16:55:37.354418 Assembling file list
[Container] 2023/12/02 16:55:37.354429 Expanding dist
[Container] 2023/12/02 16:55:37.355866 Expanding file paths for base directory dist
[Container] 2023/12/02 16:55:37.355878 Assembling file list
[Container] 2023/12/02 16:55:37.355881 Expanding css/**/*
[Container] 2023/12/02 16:55:37.357400 Found 2 file(s)
[Container] 2023/12/02 16:55:37.358485 Phase complete: UPLOAD_ARTIFACTS State: SUCCEEDED
[Container] 2023/12/02 16:55:37.358497 Phase context status code:  Message: 

Please help!!! Thank you in advance.

I tried different path combinations like "dist/app" to see if it work but nothing worked. I have wasted 4 hours on this reading the docs Build specification reference for CodeBuild - AWS CodeBuild (amazon.com) . But did not find what I am doing wrong.

asked 5 months ago227 views
2 Answers
0

Hello.

How about trying to find where the "app" directory is using the "find" command?
You may be able to find out where the "app" directory is from the results of running the following command in the "post_build" phase etc.

find  ./dist/ -type d
profile picture
EXPERT
answered 5 months ago
  • Hi. The "app" is not a directory, but a executable generated by "go build" command of Golang.

  • If it's a file, wouldn't you be able to find it by setting the option to "-f"?

    find  ./dist/ -type f
    
  • Looking at the log, it appears that "go build" is outputting to "dist/bin/app", but is there no app file in the "dist/bin/" directory?

    go build -ldflags="-X 'subrataaich.com/go/server.env=prod'" -o dist/bin/app
    
  • What will happen if all files are uploaded using "files" in buildspec.yml? For example, if I do the following, all files should be uploaded, but will the "app" file be skipped in this case as well?

    artifacts:
      files:
        - "**/*"
    
    
  • Yes. This works perfectly. This is what I did initially. But this is not what I need. I need to do pick particular files and folders from the dist folder and not all of them.

    Apart from these, can you explain what "Expanding..." means in the log file?

0

The "go build" command outputs the executable in the dist folder. I forgot to update the question before posting. Now I have updated the question. Apologies for my ignorance.

And yes the "app" executable does exist in the dist folder as you can see here in the output log -

Container] 2023/12/02 16:55:36.427725 Entering phase POST_BUILD
[Container] 2023/12/02 16:55:36.428423 Running command cd dist && pwd && ls -al
/codebuild/output/src260768698/src/git-codecommit.ap-south-1.amazonaws.com/v1/repos/subrataaich.com/dist
total 180
drwxr-xr-x  7 root root    172 Dec  2 16:55 .
drwxr-xr-x 10 root root   4096 Dec  2 16:55 ..
-rw-r--r--  1 root root    490 Dec  2 16:55 appspec.yml
drwxr-xr-x  2 root root     17 Dec  2 16:55 app
drwxr-xr-x  2 root root     54 Dec  2 16:55 css
drwxr-xr-x  2 root root     58 Dec  2 16:55 html
drwxr-xr-x  4 root root    245 Dec  2 16:55 js
drwxr-xr-x  2 root root     37 Dec  2 16:55 scripts
-rw-r--r--  1 root root   1399 Dec  2 16:55 sw.js
-rw-r--r--  1 root root   3772 Dec  2 16:55 sw.js.map
-rw-r--r--  1 root root  15119 Dec  2 16:55 workbox-3e911b1d.js
-rw-r--r--  1 root root 148299 Dec  2 16:55 workbox-3e911b1d.js.map

The artifacts are uploaded to S3 bucket. After CodeBuild was done, I checked the uploaded artifact but there were all the files except the executable.

I tried different output path with go build to see if the problem goes away. I even tried gzipping the executable. I also tried changing the executable permission to 644. But nothing worked.

answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions