How to deploy maven project on aws with Gitlab CI/CD

試著忘記壹切 提交于 2019-12-11 15:54:39

问题


I'm trying to deploy a java maven project on aws with Gitlab CI/CD.

This is my .gitlab-ci.yml


image: maven:3-jdk-8
services:
    - docker:dind

stages:
    - test
    - build
    - deploy

maven-test:
    stage: test
    script:
        - echo "Test stage"
        - mvn clean validate compile test -B


maven-build:
    stage: build
    script:
        - echo "Build stage"
        - mvn install -B -DskipTests
    artifacts:
        paths:
            - ./target/*.jar

maven-deploy:
    stage: deploy
    script:
        - echo "Deploy stage"
        - scp -v -o StrictHostKeyChecking=no -I "mykey.pem" ./target/*.jar ubuntu@xxxxxxx.com:*.jar
    when: manual


If I execute the scp command on a terminal in my pc then the jar is uploaded in aws ec2 instance while in gitlab I have errors and the jar is not uploaded.

This is my first approach with Gitlab CI and aws, so can someone explain step by step what I need to do to deploy the project in aws ec2 instance with Gitlab CI?

Thanks!


回答1:


Since you have not posted much about your problem nor did you post the error I will just suggest a few things to look at:

From a GitLab perspective:

  1. Are you sure that the "mykey.pem" is available within the repository when running that command(maven-deploy) on the the gitlab-runner.?
  2. Also are you sure that you are using a docker gitlab-runner, if you are not then you can't use the image: directive and therefore it might not not have mvn/scp locally.
  3. You might want to look into the dependencies directive and ensure you make that artifact available in next task. This should be done by default!

From an AWS perspective:

  1. Make sure that the ubuntu target machine/server has port 22 exposed to the EC2 machine running the gitlab-runner.

Edit:

If the error you are receiving is with the pem files permissions then take a look at this resolution for AWS EC2 pem file issue. Another similar resolution is here.

Seems like if you put chmod 400 mykey.pem before the scp it might fix your problem.



来源:https://stackoverflow.com/questions/57612422/how-to-deploy-maven-project-on-aws-with-gitlab-ci-cd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!