Search code examples
amazon-s3circlecicircleci-2.0

Difficults deploying circleci v.2 to AWS S3


I'm a newbie to to CI/CD stuff and I've been trying for a couple of days to deploy an application to our bucket at AWS S3.

I tried this: https://medium.freecodecamp.org/how-to-set-up-continuous-deployment-to-aws-s3-using-circleci-in-under-30-minutes-a8e268284098

this: https://circleci.com/docs/1.0/continuous-deployment-with-amazon-s3/

And this: https://medium.com/@zlwaterfield/circleci-s3-upload-dbffa0956b6f

But somehow I wasn't able to succeed with my attempt to do so. Circleci says my file successful was build, but somehow no deploy was made and no error msg was received. My AWS permissions are set, so it's being really frustrating this task.

Here's my final file:

jobs: 
  build: 
    docker: 
      - 
        image: "circleci/openjdk:8-jdk"
    environment: 
      JVM_OPTS: "-Xmx3200m"
      TERM: dumb
    steps: 
      - checkout
      - 
        restore_cache: 
          keys: 
            - "v1-dependencies-{{ checksum \"build.gradle\" }}"
            - v1-dependencies-
      - 
        run: "gradle dependencies"
      - 
        save_cache: 
          key: "v1-dependencies-{{ checksum \"build.gradle\" }}"
          paths: 
            - ~/.gradle
      - 
        run: "gradle test"
    working_directory: ~/repo
  deploy: 
    machine: 
      enabled: true
    steps: 
      - 
        run: 
          command: 'aws s3 sync ${myAppName}/ s3://${myBucketName} --region us-west-2'
          name: Deploy
    working_directory: ~/repo
version: 2

Solution

  • Updated: I was able to find a way. Here's my solution in case anyone needs it:

     jobs: 
      build: 
        docker: 
          - 
            image: "circleci/openjdk:8-jdk"
        environment: 
          JVM_OPTS: "-Xmx3200m"
          TERM: dumb
        steps: 
          - checkout
          - 
            restore_cache: 
              keys: 
                - "v1-dependencies-{{ checksum \"build.gradle\" }}"
                - v1-dependencies-
          - 
            run: "gradle dependencies"
          - 
            save_cache: 
              key: "v1-dependencies-{{ checksum \"build.gradle\" }}"
              paths: 
                - ~/.gradle
          - 
            run: "gradle build"
          - 
            run: "gradle test"
          - run: 
              command: "sudo apt-get -y -qq install awscli"
              name: "Install awscli"
          - 
            run: 
              command: "aws configure list"
              name: "show credentials"
          - 
            run: 
              command: "aws s3 ls"
              name: "List all buckets"
          - 
            run: 
              command: "aws s3 sync /tmp/app/myProject/build/libs s3://my-aws-bucket"
              name: "Deploy to my AWS bucket"
            working_directory: /tmp/app
        version: 2
        workflows: 
          build-deploy: 
            jobs: 
              - 
                build-job: 
                  filters: 
                    branches: 
                      only: 
                        - /development.*/
                        - /staging.*/
          version: 2