Skip to content

Commit

Permalink
Merge pull request #30 from mrmilu/DEVOPS-500-update-cicd
Browse files Browse the repository at this point in the history
DEVOPS-500 update cicd file
  • Loading branch information
ikerblanco-mrmilu authored Oct 7, 2024
2 parents c939ba3 + 9a95ca1 commit 27638ab
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 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:
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,40 +43,35 @@ 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
secrets: |
"next_env_variables=${{ secrets.NEXT_ENV_VARIABLES}}"
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 --force-recreate -d --remove-orphans 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 }}"

0 comments on commit 27638ab

Please sign in to comment.