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

Commit

Permalink
tools: add 'artifacts' target
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoutschen committed Mar 2, 2020
1 parent c14969c commit 8edd586
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 229 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ ci-%:
@${MAKE} build-$*
@${MAKE} tests-unit-$*

# Artifacts services
artifacts: $(foreach service,${SERVICES_ENVONLY}, all-${service})
artifacts-%:
@echo "[*] $(ccblue)artifacts $*$(ccend)"
@${MAKE} -C $* artifacts

# Build services
build: $(foreach service,${SERVICES}, build-${service})
build-%:
Expand Down
4 changes: 2 additions & 2 deletions pipeline/resources/buildspec-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ phases:
# Tests for all services must work before moving to the next step
- |
for SERVICE in $(tools/services --changed-since $COMMIT_ID); do
make ci-$SERVICE package-$SERVICE || exit 1
make ci-$SERVICE package-$SERVICE artifacts-$SERVICE || exit 1
done
# Upload template artifacts to 'templates/$SERVICE.yaml'
# This will trigger the pipelines per service
- |
for SERVICE in $(tools/services --changed-since $COMMIT_ID); do
tools/pipeline upload $SERVICE || exit 1
aws s3 cp $SERVICE/artifacts.zip s3://$S3_BUCKET/templates/$SERVICE.zip || exit 1
done
# Update the parameter
- aws ssm put-parameter --name $COMMIT_PARAMETER --type String --value $CODEBUILD_RESOLVED_SOURCE_VERSION --overwrite
3 changes: 3 additions & 0 deletions shared/makefiles/cfn-nocode.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export ENVIRONMENT ?= dev
export ROOT ?= $(shell dirname ${CURDIR})
export SERVICE ?= $(shell basename ${CURDIR})

artifacts:
@${ROOT}/tools/artifacts cloudformation ${SERVICE}

build:
@${ROOT}/tools/build resources ${SERVICE}
@${ROOT}/tools/build openapi ${SERVICE}
Expand Down
3 changes: 3 additions & 0 deletions shared/makefiles/cfn-python3.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export ENVIRONMENT ?= dev
export ROOT ?= $(shell dirname ${CURDIR})
export SERVICE ?= $(shell basename ${CURDIR})

artifacts:
@${ROOT}/tools/artifacts cloudformation ${SERVICE}

build:
@${ROOT}/tools/build resources ${SERVICE}
@${ROOT}/tools/build openapi ${SERVICE}
Expand Down
3 changes: 3 additions & 0 deletions shared/makefiles/empty.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ export ENVIRONMENT ?= dev
export ROOT ?= $(shell dirname ${CURDIR})
export SERVICE ?= $(shell basename ${CURDIR})

artifacts:
$(error "Target $@ is not implemented.")

build:
$(error "Target $@ is not implemented.")
.PHONY: build
Expand Down
81 changes: 81 additions & 0 deletions tools/artifacts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

set -e

ROOT=${ROOT:-$(pwd)}
TYPE=$1
SERVICE=$2

service_dir=$ROOT/$SERVICE
build_dir=$service_dir/build

display_usage () {
echo "Usage: $0 TYPE SERVICE"
}

# Check if there are at least 2 arguments
if [ $# -lt 2 ]; then
display_usage
exit 1
fi

# Check if the service exists
if [ ! -f $service_dir/metadata.yaml ]; then
echo "Service $SERVICE does not exist"
exit 1
fi

# Check for quiet mode
if [ ! -z $QUIET ]; then
export OUTPUT_FILE=$(mktemp)
exec 5>&1 6>&2 1>$OUTPUT_FILE 2>&1
fi

cleanup () {
CODE=$?
if [ ! -z $QUIET ]; then
if [ ! $CODE -eq 0 ]; then
cat $OUTPUT_FILE >&5
fi
rm $OUTPUT_FILE
fi
}
trap cleanup EXIT

artifacts_cloudformation () {
if [ ! -d $build_dir ]; then
echo "$build_dir does not exist."
exit 1
fi

template_file=$build_dir/template.out
if [ ! -f $template_file ]; then
echo "$template_file does not exist."
exit 1
fi

# Create a temporary folder
tmpdir=$(mktemp -d)

# Copy artifacts
cp -pv $template_file $tmpdir/template.yaml
for artifact_file in $build_dir/artifacts/*; do
cp -pv $artifact_file $tmpdir/$(basename $artifact_file)
done

# Create zip file
pushd $tmpdir
zip $build_dir/artifacts.zip *
popd

# Delete the temporary folder
rm -r $tmpdir
}

type artifacts_$TYPE | grep -q "function" &>/dev/null || {
echo "Unsupported type: $TYPE"
echo
display_usage
exit 1
}
artifacts_$TYPE
2 changes: 1 addition & 1 deletion tools/clean
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ clean () {
echo "Removing $build_dir"
rm -r $build_dir
else
echo "$build_dir does not exit. Skipping"
echo "$build_dir does not exist. Skipping"
fi
}

Expand Down
226 changes: 0 additions & 226 deletions tools/pipeline

This file was deleted.

0 comments on commit 8edd586

Please sign in to comment.