Trying to build AWS Lambda functions using docker and gitlab-ci, struggling to understand where to draw the line between the Docker image and the script to execute.
Hi all, I've been struggling with this one for a while and haven't been able to figure it out.
I am adding ci/cd to my aws cloud app and would like to build + deploy some lambda functions + cloudformation stack + some docker containers to fargate.
I have a build script which uses yarn and typescript to compile the lambda functions. Then, it uses AWS sam to deploy them. On my local machine, it's a straightforward bash script. The build and bundle-functions command use typescript + zip:
#!/bin/bash
LAMBDA_CODE_DIRECTORY='./services/lambdas/code'
# lambda.1. Build lambda functions
cd $LAMBDA_CODE_DIRECTORY &&
yarn install &&
yarn run build &&
yarn run bundle-functions
My migration plan was to write a Dockerfile that I could build and then run locally -- the code would be added, built, and deployed at runtime. Then, I would build that dockerfile and use it as the image for my gitlab ci pipeline when it was working correctly.
The Dockerfile I was getting started with is:
FROM lambci/lambda:build-nodejs10.x
ENV AWS_DEFAULT_REGION us-east-1
RUN npm install -g yarn
And to build, run: docker build -t yarn-test . ... docker run -t test yarn. Which works! However, when integrating with Gitlab, it seems like docker uses sh to run tasks; and I do not understand how to call the yarn command in that context. I have similar difficulty when trying to call aws-sam or aws-cli in Gitlab, even though I can see the expected output when calling those packages directly with docker run -t test sam or docker run -t aws directly.
How do I configure the Dockerfile so that the "script" section of gitlab-ci can call aws cloudformation, sam, tsc (typescript compiler)?
Posted Nov 23, 2019, 12:45 AM UTC