Update CICD get url server #173
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: development | |
on: | |
pull_request: | |
branches: develop | |
push: | |
branches: | |
- develop | |
jobs: | |
build-push-image-search: | |
runs-on: ubuntu-latest | |
env: | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Cache Python dependencies | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('./image-search-engine/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip-image-search | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.9 | |
- name: Install Dependencies | |
run: pip install -r ./image-search-engine/requirements.txt | |
- name: Run isort | |
run: isort --check-only --profile=black ./image-search-engine/. | |
- name: Run black | |
run: black --check ./image-search-engine/. | |
- name: Run flake8 | |
run: flake8 --ignore=E501,W503,F401 ./image-search-engine | |
# - name: Run Pylint | |
# run: pylint ./image-search-engine/*.py | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
id: docker_hub_auth | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./image-search-engine | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/image-search-engine:latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-push-text-search: | |
runs-on: ubuntu-latest | |
env: | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Cache Python dependencies | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('./text-search-engine/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip-text-search | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: 3.9 | |
- name: Install Dependencies | |
run: pip install -r ./text-search-engine/requirements.txt | |
- name: Run isort | |
run: isort --check-only ./text-search-engine/. | |
- name: Run black | |
run: black --check ./text-search-engine/. | |
- name: Run flake8 | |
run: flake8 --ignore=E501,W503,F401 ./text-search-engine | |
# - name: Run Pylint | |
# run: pylint ./image-search-engine/*.py | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
id: docker_hub_auth | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./text-search-engine | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/text-search-engine:latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-push-backend: | |
runs-on: ubuntu-latest | |
env: | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Cache Python dependencies | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('./backend/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip-text-search | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: "3.10" | |
- name: Install Dependencies | |
run: pip install -r ./backend/requirements.txt | |
- name: Run isort | |
run: isort --check-only --profile=black ./backend/. | |
- name: Run black | |
run: black --check ./backend/. | |
- name: Run flake8 | |
run: flake8 --ignore=E501,W503,F401 ./backend | |
# - name: Run Pylint | |
# run: pylint ./backend/*.py | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
id: docker_hub_auth | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./backend | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/backend-search-engine:latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-push-frontend: | |
runs-on: ubuntu-latest | |
env: | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | |
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} | |
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} | |
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
id: docker_hub_auth | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Add env variable to env file | |
run: | | |
echo GOOGLE_CLIENT_ID=${{ env.GOOGLE_CLIENT_ID }} >> ./frontend/.env | |
echo GOOGLE_CLIENT_SECRET=${{ env.GOOGLE_CLIENT_SECRET }} >> ./frontend/.env | |
echo NEXTAUTH_SECRET=${{ env.NEXTAUTH_SECRET }} >> ./frontend/.env | |
- name: Build and push frontend image | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./frontend | |
file: ./frontend/Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/frontend-search-engine:latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
create-infrastructure: | |
runs-on: ubuntu-latest | |
needs: | |
- build-push-image-search | |
- build-push-text-search | |
- build-push-backend | |
- build-push-frontend | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v2 | |
- name: Configure AWS credentials | |
id: creds | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-1 | |
- name: Deploy to AWS CloudFormation | |
uses: aws-actions/aws-cloudformation-github-deploy@v1 | |
with: | |
name: server | |
template: ./.github/workflows/cloudformations/server.yml | |
parameter-overrides: "file:///${{ github.workspace }}/.github/workflows/cloudformations/server-parameters.json" | |
tags: ${{ vars.TAGS }} | |
- name: Get Public DNS Server | |
run: | | |
# Create file | |
backend_public_dns=server-PublicDNS | |
# Pull the export value | |
host=$(aws cloudformation list-exports \ | |
--query "Exports[?Name==\`$backend_public_dns\`].Value" \ | |
--no-paginate --output text) | |
echo $host | |
# Append the DNS to the inventory file | |
echo $host >> $(eval echo "./.github/workflows/ansible/hosts") | |
cat ./.github/workflows/ansible/hosts | |
- name: Run playbook | |
uses: dawidd6/action-ansible-playbook@v2 | |
with: | |
# Required, playbook filepath | |
playbook: deploy_applications.yml | |
# Optional, directory where playbooks live | |
directory: ./.github/workflows/ansible | |
# Optional, SSH private key | |
key: ${{secrets.SSH_PRIVATE_KEY}} | |
# # Optional, literal inventory file contents | |
# inventory: | | |
# [all] | |
# ec2-3-87-235-66.compute-1.amazonaws.com | |
options: | | |
--inventory ./hosts | |
# - name: Setting up SSH key | |
# run: | | |
# echo "${{ secrets.SSH_PRIVATE_KEY }}" > private_key.pem | |
# chmod 600 private_key.pem | |
# - name: Run Ansible Playbook | |
# run: | | |
# sudo apt update | |
# sudo apt install -y ansible | |
# cd ./.github/workflows/ansible | |
# ansible-playbook -i hosts deploy_applications.yml --private-key=private_key.pem | |
- name: Setup SSH | |
shell: bash | |
run: | | |
eval `ssh-agent -s` | |
mkdir -p /home/runner/.ssh/ | |
touch /home/runner/.ssh/id_rsa | |
echo -e "${{secrets.SSH_PRIVATE_KEY}}" > /home/runner/.ssh/id_rsa | |
chmod 700 /home/runner/.ssh/id_rsa | |
ssh-keyscan -t rsa,dsa,ecdsa,ed25519 ${{secrets.SSH_HOST}} >> /home/runner/.ssh/known_hosts | |
- name: Run ansible script | |
shell: bash | |
run: | | |
sudo apt update | |
sudo apt install -y ansible | |
service ssh status | |
cd ./.github/workflows/ansible | |
hosts | |
ansible-playbook -vvv --private-key /home/runner/.ssh/id_rsa -i hosts deploy_applications.yml |