Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Java Deployment

Meetup "Vienna System Architects" 2013/12/02
by

Philipp Krenn

on 3 December 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Java Deployment

Java
Deployment

Scenario
First Try
Trying Again
Unified Build +
Environment
More Problems
Prod vs Dev:
Dedicated Pull Request builds (integrated into GitHub)
How to untangle the dependencies for Dev and Prod environments?
Outlook & Discussion
Java + Maven
Spring Profiles
Super POM
Accesslayer
Rendering
Frontend-Library
SFTP
SMTP
IMAP
Administration
Frontend1
Frontend2
4 Internal libraries
5 Parent-module projects
15 Deployment artifacts
Environments:
Prod
Stage
Dev
Local
Test
CI
Frontend1 local.properties:
MongoDB.host=127.0.0.1
MongoDB.port=8082
MongoDB.database=frontend_local
MongoDB.user=root
MongoDB.password=secret
Spring Config Bean:
@Configuration
@Profile({"default","local"})
@PropertySource("classpath:local.properties")
static class Local {
}

env.getProperty("MongoDB.host")
Maven:
$ mvn clean deploy -Dspring.profiles.active=ci
Requirements
Requirements:
Tested
Repeatable
Easy to deploy
Maven releases
WAR and JAR (Tanuki Service Wrapper) artifacts
Promoted Build
1) Build and test the project
2) Promote if satisfied
3) Build the desired artifact
4) Copy artifact to S3
5) Deploy to instances
Error inside the S3 plugin
Use shell instead
if [[ ! -d s3cmd/ ]]
then
wget http://sourceforge.net/projects/s3tools/files/s3cmd/1.5.0-alpha3/s3cmd-1.5.0-alpha3.tar.gz
tar -xzvf s3cmd-1.5.0-alpha3.tar.gz
mv s3cmd-1.5.0-alpha3/ s3cmd/
fi

sudo /opt/jenkins/sbin/mount-webdav https://repository-xxx.forge.cloudbees.com/private xxx
s3cmd/s3cmd put --config=/private/xxx/s3cfg artifact/frontend1/target/*.war s3://xxx.artifacts/dev/frontend1/
Deployment script:
#!/bin/bash

# Change according to the environment
HOST="ftp0.dev.xxx.com"
PROJECT="ftp"
DOWNLOAD="ftp-latest-app.zip?AWSAccessKeyId=xxx&Expires=xxx&Signature=xxx"
ENVIRONMENT="dev"

NOW=`date +"%Y_%m_%d"`
FILENAME=$PROJECT-$NOW-app.zip
TO="operations@xxx.com"

cd ~
wget "http://xxx.artifacts.s3.amazonaws.com/$ENVIRONMENT/$PROJECT/$DOWNLOAD" --output-document=$FILENAME

if [ -f $FILENAME ]
then

# Unzip the new, stop and remove the old version
unzip ~/$FILENAME
sudo /etc/init.d/$PROJECT stop
cd /opt/$PROJECT/
rm -fR *

# Start the new version
sudo /etc/init.d/$PROJECT start

# Archive the downloaded file
mv ~/$FILENAME ~/archive-$PROJECT/

# Wait for a minute, check the status afterwards, and email the result
sleep 60
/etc/init.d/$PROJECT status > /dev/null
if [ $? -eq 0 ]
then
SUBJECT="Deployment SUCCESS on $HOST ($PROJECT.$ENVIRONMENT)"
else
SUBJECT="Deployment FAILURE on $HOST ($PROJECT.$ENVIRONMENT) - service not running"
fi
mail -s "$SUBJECT" "$TO" < logs/wrapper.log

else
echo "The downloaded file is missing" 2>&1
echo "Missing ZIP file" | mail -s "Deployment FAILURE on $HOST - missing file" "$TO"
fi
Problems:
MissingProjectException / wrong version
SNAPSHOT dependencies
Same as before, but
Load environment from the instance
Build all artifacts on the initial run
Only copy inside the promotion job
Jenkins:
Post-build action: Archive artifacts (fast)
Copy artifacts from another project: Specified by permalink
Some Tricks
Use different colors for promotion jobs
Wipe repository (if needed?)
Add information to the artifacts
Encrypt properties
Pre Steps: Execute shell
rm -f frontend1/*.version
echo ${BUILD_ID} > "frontend1/${BUILD_NUMBER}.version"
echo `git rev-parse HEAD` >> "frontend1/${BUILD_NUMBER}.version"
Encrypt properties (http://ejohn.org/blog/keeping-passwords-in-source-control/)
#!/bin/sh
set -e

echo "Contact operations@xxx.com for the password"
FILE=$1
FILENAME=$(basename "$FILE")
EXTENSION="${FILENAME##*.}"
NAME="${FILENAME%.*}"

if [[ "$EXTENSION" == "properties" ]]
then
echo "Encrypting $FILENAME and removing the plaintext file"
openssl aes-256-cbc -e -a -in $FILENAME -out ${FILENAME}.aes256
rm $FILENAME
elif [[ "$EXTENSION" == "aes256" ]]
then
echo "Decrypting $FILENAME"
openssl aes-256-cbc -d -a -in $FILENAME -out $NAME
else
echo "Unknown extension $EXTENSION, aborting"
fi
Desired:
Jenkins

Non-requirements:
Automatic deployment
Restart:
/etc/rc.local loaded too late
Daemonize with svc (DJ Bernstein)
Philipp Krenn
@xeraa

Environment
Full transcript