Skip to content

Commit a251dac

Browse files
Merge pull request #2 from iopipe/updates
Updates to Log4J2 Adapter
2 parents 1d63aef + 03adf13 commit a251dac

File tree

6 files changed

+318
-10
lines changed

6 files changed

+318
-10
lines changed

.circleci/config.yml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,29 @@ jobs:
4040
- checkout
4141
- run:
4242
name: Maven release
43-
command: mvn deploy -Drevision=$CIRCLE_TAG
43+
command: .circleci/release.sh
44+
publish:
45+
docker:
46+
- image: circleci/openjdk:8-jdk
47+
working_directory: ~/repo
48+
environment:
49+
MAVEN_OPTS: -Xmx3200m
50+
steps:
51+
- checkout
52+
- run:
53+
name: Install Python PIP
54+
command: sudo apt-get update && sudo apt-get install python-pip
55+
- run:
56+
name: Install publish dependencies
57+
command: sudo pip install -U awscli
58+
- run:
59+
name: Override AWS Credentials
60+
command: |
61+
echo 'export AWS_ACCESS_KEY_ID="$LAYER_AWS_ACCESS_KEY_ID"' >> $BASH_ENV
62+
echo 'export AWS_SECRET_ACCESS_KEY="$LAYER_SECRET_ACCESS_KEY"' >> $BASH_ENV
63+
- run:
64+
name: Publish layers
65+
command: .circleci/layers.sh
4466

4567
workflows:
4668
version: 2
@@ -51,7 +73,17 @@ workflows:
5173
filters:
5274
tags:
5375
only:
54-
- /^\d\.\d\.\d\w{0,5}$/
76+
- /^\d{1,}\.\d{1,}\.\d{1,}\w{0,}$/
77+
branches:
78+
ignore:
79+
- /.*/
80+
publish:
81+
jobs:
82+
- publish:
83+
filters:
84+
tags:
85+
only:
86+
- /^\d{1,}\.\d{1,}\.\d{1,}\w{0,}$/
5587
branches:
5688
ignore:
5789
- /.*/

.circleci/latestlayerversion.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash -e
2+
3+
REGIONS=(
4+
ap-northeast-1
5+
ap-northeast-2
6+
ap-south-1
7+
ap-southeast-1
8+
ap-southeast-2
9+
ca-central-1
10+
eu-central-1
11+
eu-west-1
12+
eu-west-2
13+
eu-west-3
14+
#sa-east-1
15+
us-east-1
16+
us-east-2
17+
us-west-1
18+
us-west-2
19+
)
20+
21+
echo ""
22+
echo "java8:"
23+
echo ""
24+
25+
for region in "${REGIONS[@]}"; do
26+
latest_arn=$(aws --region $region lambda list-layer-versions --layer-name IOpipeJava8LoggerLog4J2 --output text --query "LayerVersions[0].LayerVersionArn")
27+
echo "* ${region}: \`${latest_arn}\`"
28+
done

.circleci/layers.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/sh -e
2+
3+
# Need this to publish
4+
if ! which aws
5+
then
6+
echo "No AWS command"
7+
exit 1
8+
fi
9+
10+
# Package JAR and place all dependencies into the target
11+
mvn clean
12+
mvn package -Dmaven.test.skip=true
13+
mvn dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=target
14+
15+
# Copy target JARs to library directory
16+
rm -rvf java
17+
mkdir -p java/lib/
18+
cp -v target/*.jar java/lib/
19+
20+
# ZIP it up
21+
rm -f java8.zip
22+
zip -rq java8.zip java
23+
24+
# Unique identification for this release
25+
__gh="$(git rev-parse HEAD)"
26+
27+
# The S3 file key
28+
__s3="iopipe-java8-logger-log4j2/$__gh.zip"
29+
30+
# Upload for each region
31+
for __region in ap-northeast-1 ap-northeast-2 ap-south-1 ap-southeast-1 ap-southeast-2 ca-central-1 eu-central-1 eu-west-1 eu-west-2 eu-west-3 us-east-1 us-east-2 us-west-1 us-west-2
32+
do
33+
# The destination bucket, since it is region specific
34+
__bn="iopipe-layers-$__region"
35+
36+
# Upload to S3 bucket first
37+
echo "Uploading to S3 in region $__region..."
38+
aws --region "$__region" s3 cp java8.zip "s3://$__bn/$__s3"
39+
40+
# Publish layer, but we need the version
41+
echo "Publishing..."
42+
__ver="`aws lambda publish-layer-version \
43+
--layer-name IOpipeJava8LoggerLog4J2 \
44+
--content "S3Bucket=$__bn,S3Key=$__s3" \
45+
--description 'IOpipe Layer Java 8 (Log4J2 Logger)' \
46+
--compatible-runtimes java8 \
47+
--license-info 'Apache 2.0' \
48+
--region $__region \
49+
--output text \
50+
--query Version`"
51+
if [ -z "$__ver" ]
52+
then
53+
echo "Failed to publish!"
54+
exit 2
55+
fi
56+
echo "Published version $__ver"
57+
58+
# Set permissions
59+
echo "Setting permissions..."
60+
aws lambda add-layer-version-permission \
61+
--layer-name IOpipeJava8LoggerLog4J2 \
62+
--version-number "$__ver" \
63+
--statement-id public \
64+
--action lambda:GetLayerVersion \
65+
--principal "*" \
66+
--region "$__region"
67+
echo "Permissions set"
68+
done
69+

.circleci/release.sh

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/bin/sh
2+
3+
# The API is documented here:
4+
# https://www.jfrog.com/confluence/display/BT/Bintray+REST+API
5+
6+
# Environment variables used
7+
if [ -z "$BINTRAY_USER" ]
8+
then
9+
echo "BINTRAY_USER not set".
10+
exit 9
11+
fi
12+
if [ -z "$BINTRAY_API_KEY" ]
13+
then
14+
echo "BINTRAY_API_KEY not set, this is your API key in your profile."
15+
exit 9
16+
fi
17+
if [ -z "$SONATYPE_USERTOKEN" ]
18+
then
19+
echo "SONATYPE_USERTOKEN not set."
20+
exit 9
21+
fi
22+
23+
if [ -z "$SONATYPE_PASSWORDTOKEN" ]
24+
then
25+
echo "SONATYPE_PASSWORDTOKEN not set."
26+
exit 9
27+
fi
28+
29+
# Export these
30+
export BINTRAY_SUBJECT="iopipe"
31+
export BINTRAY_REPO="iopipe-logger-log4j2"
32+
export BINTRAY_PACKAGE="iopipe"
33+
34+
# And realpath
35+
if ! which realpath
36+
then
37+
echo "No realpath exists (from GNU Coreutils)"
38+
exit 9
39+
fi
40+
41+
# Get the version from the POM
42+
# This should extract the version although it could also break in
43+
# another locale, so hopefully it is not too troublesome
44+
__pom_ver="`MAVEN_OPTS="-Dorg.slf4j.simpleLogger.defaultLogLevel=OFF
45+
-Dorg.slf4j.simpleLogger.log.org.apache.maven.plugins.help=INFO"
46+
mvn help:evaluate --batch-mode -Dexpression=project.version 2>&1 | \
47+
grep -v '^\[INFO' | grep -v '^[dD]ownload' | \
48+
grep '^[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}' | \
49+
tail -n 1 | sed 's/[ \t]*//g' | sed 's/-SNAPSHOT//g'`"
50+
51+
# Note it
52+
echo "POM version: $__pom_ver" 1>&2
53+
54+
# Build
55+
mkdir -p "/tmp/$$/"
56+
if ! mvn deploy "-DaltDeploymentRepository=file::default::file:///tmp/$$/"
57+
then
58+
echo "Failed to build distribution"
59+
exit 2
60+
fi
61+
62+
# *** Create new version
63+
# HTTP -> POST /packages/:subject/:repo/:package/versions
64+
# BODY -> {
65+
# "name": "1.1.5",
66+
# "released": "ISO8601 (yyyy-MM-dd'T'HH:mm:ss.SSSZ)", (optional)
67+
# "desc": "This version...",
68+
# "github_release_notes_file": "RELEASE.txt", (optional)
69+
# "github_use_tag_release_notes": true, (optional)
70+
# "vcs_tag": "1.1.5" (optional)
71+
# }
72+
# RESULT -> Status: 201 Created
73+
# {Version get JSON response}
74+
if ! echo '{"name":"'$__pom_ver'", "desc":"'$__pom_ver'"}' | curl --data-binary @- -f -XPOST -u "$BINTRAY_USER:$BINTRAY_API_KEY" -H "Content-Type: application/json" \
75+
"https://api.bintray.com/packages/$BINTRAY_SUBJECT/$BINTRAY_REPO/$BINTRAY_PACKAGE/versions"
76+
then
77+
echo "Failed to create version!"
78+
exit 3
79+
fi
80+
81+
# Go through every built file and upload them
82+
# Ignore maven metadata because we do not care about those
83+
for __file in $(find "/tmp/$$/" -type f | grep -v maven-metadata)
84+
do
85+
# We operate on the relative path here, so we want to lose dist
86+
__as="$(realpath --relative-to="/tmp/$$/" "$__file")"
87+
88+
# *** Upload files for this version (USE THIS MAVEN PUBLISH?? WOULD IT WORK??)
89+
# HTTP -> PUT /maven/:subject/:repo/:package/:file_path[;publish=0/1]
90+
# RESULT -> Status: 201 Created
91+
# {
92+
# "message": "success"
93+
# }
94+
if ! curl --data-binary @- -f -XPUT -u "$BINTRAY_USER:$BINTRAY_API_KEY" -H "Content-Type: application/octet-stream" "https://api.bintray.com/maven/$BINTRAY_SUBJECT/$BINTRAY_REPO/$BINTRAY_PACKAGE/$__as;publish=0" < "$__file"
95+
then
96+
echo "Failed to upload $__as"
97+
98+
rm -rvf "/tmp/$$/"
99+
100+
exit 4
101+
fi
102+
done
103+
104+
# Do not need these files anymore
105+
rm -rvf "/tmp/$$/"
106+
107+
# Allow bintray to settle for a bit
108+
echo "Settling..."
109+
sleep 15
110+
111+
# *** Publish content
112+
# HTTP -> POST /content/:subject/:repo/:package/:version/publish
113+
# Status: 200 OK
114+
# RESULT -> {
115+
# "files": 39
116+
# }
117+
if ! curl -f -XPOST -u "$BINTRAY_USER:$BINTRAY_API_KEY" "https://api.bintray.com/content/$BINTRAY_SUBJECT/$BINTRAY_REPO/$BINTRAY_PACKAGE/$__pom_ver/publish"
118+
then
119+
echo "Failed to publish!"
120+
exit 5
121+
fi
122+
123+
# Allow bintray to settle for a bit
124+
echo "Settling..."
125+
sleep 15
126+
127+
# ***
128+
# HTTP -> POST /maven_central_sync/:subject/:repo/:package/versions/:version
129+
# BODY -> {
130+
# "username": "userToken", // Sonatype OSS user token
131+
# "password": "passwordToken", // Sonatype OSS user password
132+
# "close": "1" // Optional
133+
# }
134+
if ! echo '{"username":"'"$SONATYPE_USERTOKEN"'", "password":"'"$SONATYPE_PASSWORDTOKEN"'", "close": "1"}' | curl --data-binary @- -f -XPOST -u "$BINTRAY_USER:$BINTRAY_API_KEY" -H "Content-Type: application/json" \
135+
"https://api.bintray.com/maven_central_sync/$BINTRAY_SUBJECT/$BINTRAY_REPO/$BINTRAY_PACKAGE/versions/$__pom_ver"
136+
then
137+
echo "Failed to sync to maven central!"
138+
exit 5
139+
fi
140+
141+
echo "Cool it worked!"
142+

.version-rules.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" comparisonMethod="maven" xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 http://mojo.codehaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd">
3+
<ignoreVersions>
4+
<!-- Ignore alphas, betas, release candidates, and milestones. -->
5+
<ignoreVersion type="regex">(?i).*Alpha(?:-?\d+)?</ignoreVersion>
6+
<ignoreVersion type="regex">(?i).*a(?:-?\d+)?</ignoreVersion>
7+
<ignoreVersion type="regex">(?i).*Beta(?:-?\d+)?</ignoreVersion>
8+
<ignoreVersion type="regex">(?i).*-B(?:-?\d+)?</ignoreVersion>
9+
<ignoreVersion type="regex">(?i).*RC(?:-?\d+)?</ignoreVersion>
10+
<ignoreVersion type="regex">(?i).*CR(?:-?\d+)?</ignoreVersion>
11+
<ignoreVersion type="regex">(?i).*M(?:-?\d+)?</ignoreVersion>
12+
</ignoreVersions>
13+
<rules>
14+
</rules>
15+
</ruleset>

0 commit comments

Comments
 (0)