diff --git a/.github/workflows/continuous-deployment-in-ec2.yml b/.github/workflows/continuous-deployment-in-ec2.yml new file mode 100644 index 000000000..58a8c8100 --- /dev/null +++ b/.github/workflows/continuous-deployment-in-ec2.yml @@ -0,0 +1,39 @@ +name: Continuous deployment in AWS instance + +on: + push: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + env: + # mention the path where snipe-it project cloned + FILE-PATH: /home/ubuntu/Snipe-IT-GitHub-Actions + steps: + # https://github.com/rusrushal13/aws-ssm-send-command + - name: AWS SSM Send-Command + uses: rusrushal13/aws-ssm-send-command@master + id: ssm + with: + aws-region: ${{ secrets.AWS_REGION }} + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + targets: ${{ secrets.TARGETS }} + working-directory: ${{ env.FILE-PATH }} + # the below commands executes in the EC2 instance where already Snipe-IT is running. + # 1. fetch changes from remote repository. + # 2. pull the latest codes from main branch. + # 3. deploy the changes. + command: | + git fetch --all + git pull origin main + docker-compose up -d + comment: building docker containers + + # Catch SSM outputs + - name: Get the outputs + run: echo "The Command id is ${{ steps.ssm.outputs.command-id }}"