-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from mrmilu/DEVOPS-500-update-cicd
DEVOPS-500 update cicd file
- Loading branch information
Showing
1 changed file
with
31 additions
and
33 deletions.
There are no files selected for viewing
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
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 | ||
|
||
|
@@ -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 }}" |