-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GTC-1250 Update lambda layer based on any datapump source changes
The datapump was using the lambda-layer module of the gfw-lambda-layers repo. This module only updates a lambda layer if the associated Dockerfile changes, since it is mainly targeted to creating layers of existing python libraries, so only the version number in the Dockerfile matters. So, changed the terraform to build the layer.zip using the usual Dockerfile, but using the hash of the entire layer.zip to decide if the layer.zip should be uploaded to S3 and used to update the lambda. We no longer use the lambda-layer module. The layer.zip file includes all the modified times of the files, which keep changing, even when the file names and contents are the same. I tried generating a hash using only filenames and contents, but terraform seems to create its own hash of the layer.zip file as well, so basically we're always going to update the layer.zip no matter what, which seems fine. Added a bunch of explanatory comments, cleaned up some other comments.
- Loading branch information
Showing
7 changed files
with
96 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This is the same build script as in gfw-lambda-layers/terraform/modules/lambda_layer/scripts/build.sh | ||
# It builds and runs a docker as specified in ${1}/Dockerfile to create a layer.zip. | ||
|
||
set -e | ||
|
||
LAYER_PATH="${1}" | ||
IMAGE="globalforestwatch/${2}" | ||
|
||
echo -n "${LAYER_PATH}" > "${LAYER_PATH}/foo.txt" | ||
date >> "${LAYER_PATH}/foo.txt" | ||
CONTAINER_NAME="container_$(sha1sum ${LAYER_PATH}/foo.txt |cut -c 1-8)" | ||
|
||
pushd "${LAYER_PATH}" | ||
|
||
echo "BUILD image ${IMAGE}" | ||
docker build --no-cache -t "${IMAGE}" . | ||
|
||
echo "CREATE container ${CONTAINER_NAME}" | ||
docker run -itd --name "${CONTAINER_NAME}" "${IMAGE}" /bin/bash | ||
|
||
echo "COPY ZIP package to host" | ||
docker cp "${CONTAINER_NAME}":"/opt/layer.zip" layer.zip | ||
|
||
echo "STOP container" | ||
docker stop "${CONTAINER_NAME}" | ||
docker wait "${CONTAINER_NAME}" | ||
|
||
echo "REMOVE container" | ||
docker rm -f "${CONTAINER_NAME}" | ||
|
||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
# This does a hash of the zip file, but that includes all the modified times of the | ||
# files, which keep changing, even when the file names and contents are the same. I | ||
# tried generating a hash using only filenames and contents, but terraform seems to | ||
# create its own hash of the layer.zip file as well, so basically we're always going | ||
# to update the layer.zip no matter what, which seems fine. | ||
hash=$(sha256sum $1 | cut -d' ' -f1) | ||
|
||
echo '{ "hash": "'"$hash"'" }' |