Why isn't this config deploying correctly? Elixir / Phoenix AWS Deploy

So, this build passes successfully and deploy succeeds as well. But in the end, the old source code is still deployed instead of the new build. This has been driving me crazy for days. What am I doing wrong?

config.yml:

version: 2

shared: &shared
  parallelism: 1
  docker:
    - image: path.dkr.ecr.ap-northeast-1.amazonaws.com/path/app-name
      environment:
        MIX_ENV: test
        PG_HOST: localhost
        REDIS_HOST: localhost
        ES_HOST: localhost
        DOCKERIZE_VERSION: v0.6.1
    - image: circleci/postgres:9.6-alpine
      environment:
        POSTGRES_USER: db_name
        POSTGRES_DB: db_name_test
        POSTGRES_PASSWORD:
    - image: redis:3.2-alpine
    - image: path.dkr.ecr.ap-northeast-1.amazonaws.com/ap-name/app-name-es6
  steps:
    - checkout

    - run: apk add --no-cache openssl

    - run:
        name: install dockerize
        command: |
          wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
          && tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
          && rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz
    - run: mix local.hex --force
    - run: mix local.rebar --force
    - restore_cache:
        keys:
          - v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
    - run: mix do deps.get, compile
    - save_cache:
        key: v1-mix-cache-{{ .Branch }}-{{ checksum "mix.lock" }}
        paths: "deps"
    - run:
        name: Wait for DB
        command: dockerize -wait tcp://localhost:5432 -timeout 1m

    - run:
        name: Database Setup
        command: |
          mix ecto.create
          mix ecto.load
    - run: mix test --exclude pending

    - store_test_results:
        path: _build/test/junit

jobs:
  build:
    working_directory: ~/app
    <<: *shared
  deploy:
    working_directory: /opt/app
    <<: *shared
    steps:
      - setup_remote_docker:
          docker_layer_caching: true
      - run:
          name: Install dependencies
          command: |
            apk update && apk add sudo && apk add py-pip && apk add docker && apk add jq
            sudo pip install awscli
            curl -s https://raw.githubusercontent.com/silinternational/ecs-deploy/3.4.0/ecs-deploy | sudo tee -a /usr/local/bin/ecs-deploy \
              && sudo chmod +x /usr/local/bin/ecs-deploy
      - run:
          name: Execute Deployment
          command: |
            case "${CIRCLE_BRANCH}" in
            "master")
              DEPLOY_ENV="dev"
              ;;
            "deployment/dev")
              DEPLOY_ENV="dev"
              ;;
            "deployment/production")
              DEPLOY_ENV="production"
              ;;
            *)
              exit
              ;;
            esac
            bin/deploy ${DEPLOY_ENV}
workflows:
  version: 2
  pr-build:
    jobs:
      - build:
          filters:
            branches:
              ignore:
                - master
                - /deployment\/.*/
  dev-deploy:
    jobs:
      - deploy:
          filters:
            branches:
              only:
                - master
                - deployment/dev
  production-deploy:
    jobs:
      - deploy:
          filters:
            branches:
              only:
                - deployment/production

deploy script:

#!/bin/bash -e

DEPLOY_ENV=$1
DEPLOY_ENV=${DEPLOY_ENV:=dev}

case $DEPLOY_ENV in
  "dev" )
    printf "Start deployment for \e[37;44;1m ${DEPLOY_ENV} \e[m\n"
    MIX_ENV=dev ;;
  "production" )
    printf "Start deployment for \e[37;41;1m ${DEPLOY_ENV} \e[m\n"
    MIX_ENV=prod ;;
  * )
    printf "\e[35m${DEPLOY_ENV}\e[m is not valid deployment target!\n" && exit 1 ;;
esac

# Ensure source code is up to date
mix do clean, deps.clean --all, deps.get

aws s3 cp s3://secret.path/${MIX_ENV}.secret.exs config/
docker build -t path/app-name:deployment -f ./docker/Dockerfile.deployment --build-arg MIX_ENV=${MIX_ENV} .
docker tag path/app-name:deployment path.ap-northeast-1.amazonaws.com/path/app-name:${DEPLOY_ENV}
eval `aws ecr get-login --no-include-email --region ap-northeast-1`
docker push path.dkr.ecr.ap-northeast-1.amazonaws.com/path/app-name:${DEPLOY_ENV}
ecs-deploy --cluster app-name-${DEPLOY_ENV} \
  --image path.dkr.ecr.ap-northeast-1.amazonaws.com/path/app-name:${DEPLOY_ENV} \
  --service-name phoenix-upload \
  --region ap-northeast-1 \
  --timeout 300 \
  --enable-rollback

Note that the deploy script deploys correctly from local machine, so it must be the CircleCI config.

Thanks!

I am not familiar with AWS, but it strikes me you can narrow down what is happening from your build logs.

It looks like you are deploying by Docker image rather than by, say, a Git hash. Firstly, have a look at the code you are doing the docker build against. Is it the right code? You are using checkout, look at the hash it uses from your logs - is it correct?

Can you pull your image back to your local machine and work out what version it is at? That might help debugging why you are getting the wrong version.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.