Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVOPS-498 update cicd file #50

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 30 additions & 31 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
name: Deploy using SSH

name: Deploy using Ansible
on:
push:
branches:
- develop
- master

env:
REGISTRY: ghcr.io
IMAGE_NAME: "${{ github.repository }}"
IMAGE_NAME: ${{ github.repository }}
DOCKERFILE: Dockerfile
HUSKY: 0
jobs:

jobs:
build:
environment: ${{ github.ref_name == 'master' && 'production' || 'staging'}}

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Expand All @@ -40,10 +43,10 @@ jobs:
- name: Build and Push Main Image
uses: docker/build-push-action@v4
with:
context: "{{defaultContext}}"
context: .
push: true
file: Dockerfile
tags: "${{ steps.meta_main.outputs.tags }}"
file: ${{ env.DOCKERFILE }}
tags: ${{ steps.meta_main.outputs.tags }}
labels: ${{ steps.meta_main.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
Expand All @@ -53,26 +56,22 @@ jobs:
deploy:
environment: ${{ github.ref_name == 'master' && 'production' || 'staging'}}
runs-on: ubuntu-latest
needs: [build]
needs: build
steps:
- name: Deploy to Staging
uses: appleboy/[email protected]
env:
PROJECT_PATH: ${{ vars.PROJECT_PATH }}
COMPOSE_FILE: ${{ vars.COMPOSE_FILE }}

with:
host: ${{ vars.REMOTE_HOST }}
username: ${{ vars.REMOTE_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script_stop: true
envs: PROJECT_PATH,COMPOSE_FILE
script: |
export COMPOSE_INTERACTIVE_NO_CLI=1
cd $PROJECT_PATH
set -euxo pipefail
git pull
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
docker compose -f ${{ vars.COMPOSE_FILE }} pull COMPOSE_NAME
docker compose -f ${{ vars.COMPOSE_FILE }} up -d COMPOSE_NAME
- name: Deploy to ${{ github.ref_name == 'master' && 'production' || 'staging'}}
uses: appleboy/[email protected]
env:
PROJECT_PATH: ${{ vars.PROJECT_PATH }}
with:
host: ${{ vars.REMOTE_HOST }}
username: ${{ vars.REMOTE_USER}}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script_stop: true
envs: PROJECT_PATH
script: |
export COMPOSE_INTERACTIVE_NO_CLI=1
cd $PROJECT_PATH
set -euxo pipefail
git pull
ansible-playbook -i inventory/${{ github.ref_name == 'master' && 'production' || 'staging'}} site.yml --tags deploy --extra-vars "services_to_start=['front'] docker_compose_project_github_token=${{ secrets.GITHUB_TOKEN }} docker_compose_project_github_actor=${{ github.actor }}"
Loading