1
votes

I have a Spring boot application, which i am not able to deploy to AWS Ubuntu instance using AWS Code Deploy

This is the appspec.yml

version: 0.0
os: linux
files:
  - source: /
    destination: /opt/ubuntu/server

permissions:
  - object: /
    pattern: "**"
    owner: ubuntu
    group: ubuntu

hooks:
  ApplicationStop:
    - location: stop_server.sh
      timeout: 20
      runas: root
  ApplicationStart:
    - location: start_server.sh
      timeout: 300
      runas: ubuntu

stop_server.sh file

#!/usr/bin/env bash

# Kill Java process

# Determine the pid
PID=`ps -C java -o pid=`

kill -9 $PID

start_srver.sh file

#!/usr/bin/env bash
cd /opt/ubuntu/server
rm -rf target/*
sudo mvn clean package
sudo mvn spring-boot:run -Drun.jvmArguments='-Dserver.port=8080' > /dev/null 2> /dev/null < /dev/null &

CodeDeploy is stucked in Install stage, error which i am getting is mvn command not found

i logged in to instance and checked mvn command is working fine, but with codedeploy agent its not working

i have set the path ~/.profile and ~/.bashrc file, but still not working

GitHub Location of the repository is Repository Link

4

4 Answers

0
votes

codeDeploy executes as a root user so try checking if root user is having mvn installed . and ApplicationStart: - location: start_server.sh timeout: 300 runas: root instead of ubuntu run as root.

0
votes

Maven is a build system. I do not recommend to use it as part of deployment. Build the application separately (on your laptop perhaps) and use CodeDeploy to copy the code (jar file etc), and also to run some housekeeping processes (e.g. start apache service). Do not build your application on every deployment as you can see a build failure will result in deployment failure.

Looking at the error: mvn command not found

It may be better to specify the complete path of the mvn command in your scripts, e.g.:

sudo /bin/mvn clean package

Note: Please confirm the path.

0
votes

Use Code Pipeline to create the flow, integrate with Code Commit or Github repo to get the code. Use Code Build to create the necessary artifact and use the artifact in the Code Deploy. Code Build has options to create the build environment with necessary tools for eg Java Maven Docker.

0
votes

I installed maven and code deploy agent as root user in EC2 Ubuntu Instance, but still i am getting mvn command not found.

I logged in to instance and try to check mvn command it was working, but i am not able to understand why mvn command is not working with code deploy process.

Need help on this

this is appspec.yml file

version: 0.0
os: linux
files:
  - source: /
    destination: /opt/root/server

permissions:
  - object: /
    pattern: "**"
    owner: root
    group: root

hooks:
  ApplicationStop:
    - location: scripts/stop_server.sh
      timeout: 60
      runas: root
  ApplicationStart:
    - location: scripts/start_server.sh
      timeout: 60
      runas: root

start_server.sh file

mvn clean package
mvn spring-boot:run -Drun.jvmArguments='-Dserver.port=8080' > /dev/null 2> /dev/null < /dev/null &

stop_server.sh

#!/usr/bin/env bash

# Kill Java process

# Determine the pid
echo "killing process starts"
PID=`ps -C java -o pid=`

if [ -n "$PID" ]; then
    echo "killing process"
    kill -9 $PID
else
    echo "empty"
fi

cd /opt
rm -rf root