I am completing my Cloud DevOps Nanodegree program with Udacity. I am doing my third project Give Your Application Auto-Deploy Superpowers
I am getting stuck Deploy-Backend becuase I am getting random characters in my CircleCI Pipeline.
This is my end result in CircleCI Pipeline:
Here is my Deploy-Back Job in my config.yml:
deploy-backend:
docker:
- image: python:3.11-rc-alpine
steps:
- checkout
- add_ssh_keys:
fingerprints: [ 'xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx' ]
- attach_workspace:
at: ~/
- run:
name: Install dependencies
command: |
apk add --update ansible
apk add --update tar gzip nodejs npm
apk add --update --no-cache python3 py3-pip
/usr/local/bin/python -m pip install --upgrade pip
pip install awscli
- run:
name: Configure Env File
command: |
echo NODE_ENV=production >> backend/.env
echo VERSION=1 >> backend/.env
echo TYPEORM_CONNECTION=postgres >> backend/.env
echo TYPEORM_MIGRATIONS_DIR=./src/migrations >> backend/.env
echo TYPEORM_ENTITIES=./src/modules/domain/**/*.entity.ts >> backend/.env
echo TYPEORM_MIGRATIONS=./src/migrations/*.ts >> backend/.env
echo TYPEORM_HOST=$TYPEORM_HOST >> "backend/.env"
echo TYPEORM_PORT=$TYPEORM_PORT >> "backend/.env"
echo TYPEORM_USERNAME=$TYPEORM_USERNAME >> "backend/.env"
echo TYPEORM_PASSWORD=$TYPEORM_PASSWORD >> "backend/.env"
echo TYPEORM_DATABASE=$TYPEORM_DATABASE >> "backend/.env"
cat backend/.env
- run:
name: Deploy backend
command: |
cd backend
cd ..
tar -C backend -czvf artifact.tar.gz .
ls
mkdir -p /root/project
mv artifact.tar.gz /root/project/artifact.tar.gz
cd .circleci/ansible
echo "Contents of the inventory.txt file is -------"
cat inventory.txt
ansible-playbook -i inventory.txt deploy-backend.yml
- destroy-environment
- revert-migrations
These are my deploy tasks:
---
- name: "update apt packages."
become: true
apt:
update_cache: yes
- name: "upgrade packages"
become: true
apt:
upgrade: yes
- name: "install dependencies."
become: true
apt:
name: ["nodejs", "npm"]
state: latest
update_cache: yes
- name: "install pm2"
become: true
npm:
name: pm2
global: yes
production: yes
state: present
- name: Creates directory
file:
path: /home/ubuntu/backend
state: directory
- name: Copy artifact.tar.gz file
template:
src: /root/project/artifact.tar.gz
dest: /home/ubuntu/backend
- name: Uncompress Backend
shell: |
cd /home/ubuntu/backend
tar xvzf artifact.tar.gz -C .
ls -la
- name: Build
become: true
shell: |
cd /home/ubuntu/backend
npm install
npm run build
- name: Start PM2
shell: |
cd /home/ubuntu/backend
pm2 start npm --name backend -- start
