hhrzc
hhrzc

Reputation: 2059

How to clone git repository with GitLab CI-CD or how to deploy spring-boot project on AWS server?

I try to deploy the spring-boot project with GitLab CI/CD. But can't find any information that can help me.

So, I try to figure out how I can do it and created an AWS instance and run the gitlub-runner on it.

I created .gitlab-ci.yml and can copy files to the S3-bucket:

variables:
  S3_BUCKET_NAME: "awesome-proj"
deploy:
  script: aws s3 cp ./ s3://awesome-proj/ --acl bucket-owner-full-control --no-sign-request --recursive --exclude "*" --include "*.html"
  tags:
    - Tag1

I figure out I can use the console in a similar way and clone my project to the AWS server. I decided to clone the project from the git repo and build him on the server with 'maven'.

So I try to clone the project:

  S3_BUCKET_NAME: "awesome-proj"
deploy:
  script: 
    - sudo cd /home/ec2-user/aweproject
    - sudo git init
    - sudo git clone https://gitlab.com/lTer/cicdtestdev.git
  tags:
    - Tag1

These scripts even copied some data once.

enter image description here

For the second time, I got the error, but it is doesn't matter now. The problem is that I haven't any files after git clone.... So it not works how I hoped.

Upvotes: 1

Views: 3943

Answers (1)

Pierre D
Pierre D

Reputation: 26321

In principle, you don't need to clone your project. When your CI pipeline runs, it already has the appropriate clone (of a branch, or the master, of whatever the CI has been instructed to run on).

The only thing you need is to compile and then deploy. For instance:

stages:
  - compile
  - deploy

compile:
  stage: compile
  script: mvn ...
  artifacts:
    paths:
      - build/
    expire_in: 1 week

deploy:
  stage: deploy
  script: aws s3 sync build/ s3://somebucket/some_place/build/

Of course, in real life, you may want to have a specific stage for testing etc.

Upvotes: 2

Related Questions