Skip to content

Add workflow_dispatch #32

Add workflow_dispatch

Add workflow_dispatch #32

name: docker-nginx-php
on:
push:
pull_request:
workflow_dispatch:
jobs:
slack-start:
name: Notify Slack of Testing Start
runs-on: ubuntu-latest
steps:
- uses: FranzDiebold/github-env-vars-action@v2.1.0
- uses: 8398a7/action-slack@v3
with:
status: custom
fields: workflow,commit,repo,author,action,message
custom_payload: |
{
attachments: [{
color: 'warning',
text: `${process.env.AS_REPO} ${process.env.CI_REF_NAME} - Build Started :shipit: (${process.env.AS_ACTION})\n${process.env.AS_COMMIT} ${process.env.AS_MESSAGE}\n${process.env.AS_AUTHOR}`,
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()
set-deployment-image-tag:
name: Set deployment image tag
runs-on: ubuntu-latest
steps:
- uses: FranzDiebold/github-env-vars-action@v2.1.0
-
name: Get current time
uses: 1466587594/get-current-time@v2
id: current-time
with:
format: YYYYMMDDHHMMSS
-
name: Set Tag
env:
TIMESTAMP: "${{ steps.current-time.outputs.formattedTime }}"
run: echo "BUILD_IMAGE_TAG=$CI_SHA_SHORT-$TIMESTAMP" > /tmp/image_tag.env
-
name: Display Tag
run: cat /tmp/image_tag.env
-
uses: actions/upload-artifact@v2
with:
name: build-image-tag
path: /tmp/image_tag.env
set-deployment-image-name:
name: Set deployment image name
runs-on: ubuntu-latest
steps:
- uses: FranzDiebold/github-env-vars-action@v2.1.0
-
name: Set Name
run: echo "BUILD_IMAGE_NAME=nginx-php" > /tmp/image_name.env
-
name: Display Tag
run: cat /tmp/image_name.env
-
uses: actions/upload-artifact@v2
with:
name: build-image-name
path: /tmp/image_name.env
build-image:
name: Build Image
needs: [set-deployment-image-tag]
runs-on: ubuntu-latest
steps:
- uses: FranzDiebold/github-env-vars-action@v2.1.0
- uses: actions/checkout@v2
-
name: Retrieve Image Tag
uses: actions/download-artifact@v2
with:
name: build-image-tag
path: /tmp
-
name: Set Image Tag
run: cat /tmp/image_tag.env >> $GITHUB_ENV
-
name: Retrieve Image Name
uses: actions/download-artifact@v2
with:
name: build-image-name
path: /tmp
-
name: Set Image Name
run: cat /tmp/image_name.env >> $GITHUB_ENV
-
name: Get current time
uses: gerred/actions/current-time@master
id: current-time
-
name: Build Docker Image
env:
TIMESTAMP: "${{ steps.current-time.outputs.time }}"
run: |
docker build \
--build-arg BUILD_DATE=$TIMESTAMP \
--build-arg VCS_REF=$CI_REF_NAME \
--build-arg VERSION=$BUILD_IMAGE_TAG \
--tag "ghcr.io/$CI_REPOSITORY_OWNER/$BUILD_IMAGE_NAME:$BUILD_IMAGE_TAG" \
.
-
name: Login to GHCR
run: echo $GH_CONTAINER_REGISTRY_TOKEN | docker login ghcr.io -u $GH_CONTAINER_REGISTRY_USER --password-stdin
env:
GH_CONTAINER_REGISTRY_TOKEN: ${{secrets.GH_CONTAINER_REGISTRY_TOKEN}}
GH_CONTAINER_REGISTRY_USER: ${{secrets.GH_CONTAINER_REGISTRY_USER}}
-
name: Push Image to GHCR
run: docker push "ghcr.io/$CI_REPOSITORY_OWNER/$BUILD_IMAGE_NAME:$BUILD_IMAGE_TAG"
-
name: Update Branch Tag
run: docker image tag "ghcr.io/$CI_REPOSITORY_OWNER/$BUILD_IMAGE_NAME:$BUILD_IMAGE_TAG" "ghcr.io/$CI_REPOSITORY_OWNER/$BUILD_IMAGE_NAME:$CI_REF_NAME"
-
name: Push Branch Tag
run: docker push "ghcr.io/$CI_REPOSITORY_OWNER/$BUILD_IMAGE_NAME:$CI_REF_NAME"
slack-results:
name: Notify Slack of Build Results
runs-on: ubuntu-latest
needs: [build-image]
if: always()
steps:
- uses: FranzDiebold/github-env-vars-action@v2.1.0
- uses: technote-space/workflow-conclusion-action@v2
- name: Set environment variables
run: |
if [[ ${{ env.WORKFLOW_CONCLUSION }} == success ]]; then
echo 'DEPLOY_EMOJI=:rocket:' >> $GITHUB_ENV
else
echo 'DEPLOY_EMOJI=:boom:' >> $GITHUB_ENV
fi
- uses: 8398a7/action-slack@v3
with:
status: custom
job_name:
fields: workflow,job,commit,repo,ref,author,action,message
custom_payload: |
{
attachments: [{
color: '${{ env.WORKFLOW_CONCLUSION }}' === 'success' ? 'good' : '${{ env.WORKFLOW_CONCLUSION }}' === 'failure' ? 'danger' : 'warning',
text: `${process.env.AS_REPO} ${process.env.CI_REF_NAME} - ${{ env.WORKFLOW_CONCLUSION }} ${{ env.DEPLOY_EMOJI }} (${process.env.AS_ACTION})\n${process.env.AS_COMMIT} ${process.env.AS_MESSAGE}\n${process.env.AS_AUTHOR}`,
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}