Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
update terraform to provision endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
vggonzal authored and vggonzal committed Aug 5, 2023
1 parent 6d51916 commit d56204d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 62 deletions.
1 change: 1 addition & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
19 changes: 14 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
FROM public.ecr.aws/lambda/python:3.8
FROM node:10
LABEL org.opencontainers.image.source="https://github.com/podaac/hydrocron-api"
RUN npm install forever -g

COPY $SOURCE .
RUN pip3 install -t /var/task --force ./$SOURCE
ENV project_dir /project
ENV app_dir ${project_dir}/app
ENV config_dir ${project_dir}/config

# Run the lambda
CMD ["/var/task/podaac/controllers/fts_controller.lambda_handler"]
RUN mkdir ${project_dir} ${app_dir} ${config_dir}
WORKDIR ${app_dir}

COPY package*.json ./
RUN npm install
COPY . .

CMD ${app_dir}/docker/docker-start-command
48 changes: 0 additions & 48 deletions docker/README.md

This file was deleted.

24 changes: 19 additions & 5 deletions docker/build-docker.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env bash

# This script is intended to be run by the CI/CD pipeline to build a specific version of the FTS API.
# This script is intended to be run by the CI/CD pipeline to build a specific version of this application.

set -Eeo pipefail

LOCAL_BUILD=false

POSITIONAL=()
while [[ $# -gt 0 ]]
do
Expand All @@ -20,6 +22,10 @@ case $key in
shift # past argument
shift # past value
;;
--local)
LOCAL_BUILD=true
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
Expand All @@ -28,7 +34,7 @@ esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters

USAGE="USAGE: build-docker.sh -n|--service-name service_name -v|--service-version service_version"
USAGE="USAGE: build-docker.sh -n|--service-name service_name -v|--service-version service_version [--local]"

# shellcheck disable=SC2154
if [[ -z "${service_name}" ]]; then
Expand All @@ -48,13 +54,21 @@ set -u

SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
PROJECT_DIR="$(dirname "${SCRIPTPATH}")"
DIST_PATH="dist/"

repositoryName=podaac/podaac-cloud/${service_name}
app_path=$( cd ${SCRIPTPATH}/.. && echo $(pwd) )

repositoryName=ghcr.io/podaac/${service_name}

# Docker tags can't include '+' https://github.com/docker/distribution/issues/1201
dockerTagVersion=$(echo "${service_version}" | tr "+" _)

tar_filename="${service_name}-${service_version}.tar.gz"
docker build -t "${repositoryName}":"${dockerTagVersion}" --build-arg SOURCE="dist/${tar_filename}" -f "$SCRIPTPATH"/Dockerfile "$PROJECT_DIR" 1>&2
# Build the image
if [ "$LOCAL_BUILD" = true ] ; then
wheel_filename="$(echo "${service_name}" | tr "-" _)-${service_version}-py3-none-any.whl"
docker build -t "${repositoryName}":"${dockerTagVersion}" --build-arg DIST_PATH="${DIST_PATH}" --build-arg SOURCE="${DIST_PATH}${wheel_filename}" -f "$SCRIPTPATH"/Dockerfile "$PROJECT_DIR" 1>&2
else
docker build -t "${repositoryName}":"${dockerTagVersion}" --build-arg SOURCE="${service_name}==${service_version}" -f "$SCRIPTPATH"/Dockerfile "$app_path" 1>&2
fi

echo "${repositoryName}":"${dockerTagVersion}"
27 changes: 27 additions & 0 deletions docker/docker-start-command
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

outside_config_dir=/config
work_dir=/work
app_dir=/app

if [ -e "/config/server.crt" ]; then
echo "server.crt is here"
cp /config/server.crt /project/config/server.crt
fi;

if [ -e "/config/server.key" ]; then
echo "server.key is here"
cp /config/server.key /project/config/server.key
fi;

if [ -e "/config/config.js" ]; then
echo "config.js is here"
cp /config/config.js /project/config/config.js
fi;

if [ -e "/config/private-config.js" ]; then
echo "private-config.js is here"
cp /config/private-config.js /project/config/private-config.js
fi;

forever server/server.js
10 changes: 6 additions & 4 deletions docker/push-docker-ecr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ case $key in
-v|--tf-venue)
tf_venue="$2"
case $tf_venue in
sit|uat|ops) ;;
ngap-service-sit|ngap-service-uat|ngap-service-ops|ngap-cumulus-swot-sit|ngap-cumulus-sit|ngap-cumulus-swot-uat|ngap-cumulus-uat|ngap-cumulus-ops|ngap-cumulus-sndbx) ;;
*)
echo "tf_venue must be sit, uat, or ops"
exit 1;;
Expand Down Expand Up @@ -53,7 +53,7 @@ fi
set -u

repositoryName=$(echo "${docker_tag}" | awk -F':' '{print $1}')
tf_profile="ngap-service-${tf_venue}"
tf_profile="${tf_venue}"

# Get the AWS Account ID for this venue/profile
# shellcheck disable=SC2154
Expand All @@ -63,14 +63,16 @@ aws_acct=$(aws sts get-caller-identity --profile "$tf_profile" | python -c "impo
aws ecr create-repository --repository-name "${repositoryName}" --profile "$tf_profile" || echo "No need to create, repository ${repositoryName} already exists"

# Login to ECR
echo "aws ecr get-login-password --region us-west-2 --profile \"$tf_profile\" | docker login --username AWS --password-stdin \"$aws_acct\".dkr.ecr.us-west-2.amazonaws.com"
set +x
$(aws ecr get-login --no-include-email --region us-west-2 --profile "$tf_profile" 2> /dev/null) || \
docker login --username AWS --password "$(aws ecr get-login-password --region us-west-2 --profile "$tf_profile")" "$aws_acct".dkr.ecr.us-west-2.amazonaws.com
docker login --username AWS --password "$(aws ecr get-login-password --region us-west-2 --profile "$tf_profile")" "$aws_acct".dkr.ecr.us-west-2.amazonaws.com
set -x

# Tag the image for this venue's ECR
docker tag "${docker_tag}" "$aws_acct".dkr.ecr.us-west-2.amazonaws.com/"${docker_tag}"

# Push the tag
docker push "$aws_acct".dkr.ecr.us-west-2.amazonaws.com/"${docker_tag}"

# Clean up docker
docker rmi "$aws_acct".dkr.ecr.us-west-2.amazonaws.com/"${docker_tag}" || true

0 comments on commit d56204d

Please sign in to comment.