Bitbucket Pipelines with Go and Node

Published Nov 20, 2017

I wrote GitLab CI with Go last year with my .gitlab-ci.yml for building Go projects on GitLab, but I switched to Bitbucket and Bitbucket Pipelines so I figured I should post my new setup.

This is how I’m building binaries and assets for Transverse. I have two Go binaries, web and metadata, and a tar.gz with my static assets (images, templates, CSS, the minified app.min.js, etc.). Once my artifacts are built they’re uploaded to S3 so I can fetch them later during deployment.

To get started, you need to grab a couple of things:

Finally, here’s my bitbucket-pipelines.yml:

image: preetamjinka/ci:golang

    - step:
          - mkdir -pv "${PACKAGE_PATH}"
          - tar -cO --exclude-vcs --exclude=bitbucket-pipelines.yml . | tar -xv -C "${PACKAGE_PATH}"
          - cd "${PACKAGE_PATH}"
          - go test ./...                    # test Go stuff
          - cd web && npm i && npm test      # test Node.js stuff
          - cd "${PACKAGE_PATH}"
          - cd metadata && go build && cd .. # build "metadata" binary
          - cd web && go build && cd ..      # build "web" binary
          - cd web && make all && npm run build && tar czvf assets.tar.gz static templates && cd ..
          - python s3_upload.py "${S3_BUCKET}" ./metadata/metadata "transverse_metadata_${BITBUCKET_COMMIT}"
          - python s3_upload.py "${S3_BUCKET}" ./web/web "transverse_web_${BITBUCKET_COMMIT}"
          - python s3_upload.py "${S3_BUCKET}" ./web/assets.tar.gz "transverse_assets_${BITBUCKET_COMMIT}.tar.gz"