diff --git a/.github/workflows/dockerhub-deployment.yml b/.github/workflows/dockerhub-deployment.yml new file mode 100644 index 0000000..a2937e8 --- /dev/null +++ b/.github/workflows/dockerhub-deployment.yml @@ -0,0 +1,50 @@ +name: Deploy to Dockerhub + +on: + push: + tags: + - 'dockerhub-v*' + +jobs: + Release: + name: Release + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + # Getting tag name for docker image and full tag name. + - name: Get tag version + id: branch_name + run: | + echo ::set-output name=SOURCE_TAG_DOCKER_IMAGE::${GITHUB_REF#refs/tags/dockerhub-v} + echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} + + # Login to Docker + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # Build and push docker image to Dockerhub + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + push: true + tags: namikazebadri/codeigniter-app:${{ steps.branch_name.outputs.SOURCE_TAG_DOCKER_IMAGE }} + + # Outputting image digest from push + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + + # Notify engineers via slack + - name: Notify slack + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_OPEN_SOURCE }} + SLACK_USERNAME: "Open Source Activities" + SLACK_TITLE: "New Version Release!" + SLACK_MESSAGE: "\n\n === ${{ github.repository }} (${{ steps.branch_name.outputs.SOURCE_TAG }}) ===" + SLACK_FOOTER: "Powered by Element Creative Studio" + SLACK_ICON: "https://cdn.elementcreativestudio.com/github.png" \ No newline at end of file diff --git a/.github/workflows/ecr-deployment.yml b/.github/workflows/ecr-deployment.yml new file mode 100644 index 0000000..2457c65 --- /dev/null +++ b/.github/workflows/ecr-deployment.yml @@ -0,0 +1,42 @@ +name: Deploy to ECR + +on: + push: + tags: + - 'ecr-v*' + +jobs: + Release: + name: Release + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + # Getting tag name for docker image and full tag name. + - name: Get tag version + id: branch_name + run: | + echo ::set-output name=SOURCE_TAG_DOCKER_IMAGE::${GITHUB_REF#refs/tags/ecr-v} + echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} + + # Deploying image to Elastic Container Registry + - run: docker build . --tag codeigniter-app:${{ steps.branch_name.outputs.SOURCE_TAG_DOCKER_IMAGE }} + - name: Push to ECR + id: ecr + uses: jwalton/gh-ecr-push@v1 + with: + access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + region: ap-southeast-1 + image: codeigniter-app:${{ steps.branch_name.outputs.SOURCE_TAG_DOCKER_IMAGE }} + + # Notify engineers via slack + - name: Notify slack + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_OPEN_SOURCE }} + SLACK_USERNAME: "Open Source Activities" + SLACK_TITLE: "New Version Release!" + SLACK_MESSAGE: "\n\n === ${{ github.repository }} (${{ steps.branch_name.outputs.SOURCE_TAG }}) ===" + SLACK_FOOTER: "Powered by Element Creative Studio" + SLACK_ICON: "https://cdn.elementcreativestudio.com/github.png" \ No newline at end of file diff --git a/.github/workflows/gcr-deployment.yml b/.github/workflows/gcr-deployment.yml new file mode 100644 index 0000000..d613345 --- /dev/null +++ b/.github/workflows/gcr-deployment.yml @@ -0,0 +1,42 @@ +name: Deploy to GCR + +on: + push: + tags: + - 'gcr-v*' + +jobs: + Release: + name: Release + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + # Getting tag name for docker image and full tag name. + - name: Get tag version + id: branch_name + run: | + echo ::set-output name=SOURCE_TAG_DOCKER_IMAGE::${GITHUB_REF#refs/tags/gcr-v} + echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} + + # Deploying image to Google Container Registry + - name: Deploying docker image to GCR + uses: RaccoonDev/push-docker-gcr@v1 + with: + gcr_host: gcr.io + image_name: codeigniter-app + image_tag: ${{ steps.branch_name.outputs.SOURCE_TAG_DOCKER_IMAGE }} + env: + GCLOUD_SERVICE_KEY: ${{ secrets.GCLOUD_SERVICE_KEY }} + GOOGLE_PROJECT_ID: ${{ secrets.GOOGLE_PROJECT_ID }} + + # Notify engineers via slack + - name: Notify slack + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_OPEN_SOURCE }} + SLACK_USERNAME: "Open Source Activities" + SLACK_TITLE: "New Version Release!" + SLACK_MESSAGE: "\n\n === ${{ github.repository }} (${{ steps.branch_name.outputs.SOURCE_TAG }}) ===" + SLACK_FOOTER: "Powered by Element Creative Studio" + SLACK_ICON: "https://cdn.elementcreativestudio.com/github.png" \ No newline at end of file diff --git a/.github/workflows/vm-deployment.yml b/.github/workflows/vm-deployment.yml new file mode 100644 index 0000000..7fde739 --- /dev/null +++ b/.github/workflows/vm-deployment.yml @@ -0,0 +1,62 @@ +name: Deploy to VM Instance(s) + +on: + push: + tags: + - 'vm-v*' + +jobs: + Release: + name: Release + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + # Getting tag name for docker image and full tag name. + - name: Get tag version + id: branch_name + run: | + echo ::set-output name=SOURCE_TAG_DOCKER_IMAGE::${GITHUB_REF#refs/tags/vm-v} + echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} + + # Login to Docker + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # Build and push docker image to Dockerhub + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + push: true + tags: namikazebadri/codeigniter-app:${{ steps.branch_name.outputs.SOURCE_TAG_DOCKER_IMAGE }} + + # Outputting image digest from push + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + + # Deploying image to VM Machine using docker + - name: Deploying docker image to VM Machine + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SSH_HOST }} + username: ubuntu + key: ${{ secrets.SSH_PRIVATE_KEY }} + port: 22 + script: | + whoami + docker run -d -p 80:80 --name codeigniter-app namikazebadri/codeigniter-app:${{ steps.branch_name.outputs.SOURCE_TAG_DOCKER_IMAGE }} + + # Notify engineers via slack + - name: Notify slack + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_OPEN_SOURCE }} + SLACK_USERNAME: "Open Source Activities" + SLACK_TITLE: "New Version Release!" + SLACK_MESSAGE: "\n\n === ${{ github.repository }} (${{ steps.branch_name.outputs.SOURCE_TAG }}) ===" + SLACK_FOOTER: "Powered by Element Creative Studio" + SLACK_ICON: "https://cdn.elementcreativestudio.com/github.png" \ No newline at end of file