Created
September 19, 2022 13:41
-
-
Save nandenjin/be246a8133f1803f5d5f95866310f89b to your computer and use it in GitHub Desktop.
Wordpress Deployment to Cloud Run + Firebase Hosting
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
name: Deployment | |
on: deployment | |
env: | |
GCP_PROJECT: ${{ secrets.GCP_PROJECT }} | |
GCP_REGION: ${{ secrets.GCP_REGION }} | |
IMAGE: gcr.io/${{ secrets.GCP_PROJECT }}/${{.secrets.IMAGE_NAME }}:${{ github.event.deployment.environment }} | |
jobs: | |
report-deploy-start: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set deployment status to in-progress | |
uses: bobheadxi/[email protected] | |
with: | |
step: start | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: production | |
deployment_id: ${{ github.event.deployment.id }} | |
delivery: | |
needs: [report-deploy-start] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v3 | |
- name: GCP Authenticate | |
uses: 'google-github-actions/auth@v0' | |
with: | |
credentials_json: ${{ secrets.GCP_SA_KEY }} | |
export_environment_variables: true | |
create_credentials_file: true | |
- name: GCP CLI Setup | |
uses: google-github-actions/setup-gcloud@v0 | |
with: | |
project_id: ${{ secrets.GCP_PROJECT }} | |
- name: Configure docker to use the gcloud cli | |
run: gcloud auth configure-docker --quiet | |
- name: Build a docker image | |
run: DOCKER_BUILDKIT=1 docker build . -t $IMAGE | |
- name: Create Docker container | |
id: create-container | |
run: echo "::set-output name=id::$(docker create $IMAGE)" | |
- name: Create tmp directory | |
run: mkdir dist_tmp | |
- name: Copy wp-content | |
run: 'docker cp ${{ steps.create-container.outputs.id }}:/var/www/html/wp-content dist_tmp/wp-content' | |
- name: Copy wp-includes | |
run: 'docker cp ${{ steps.create-container.outputs.id }}:/var/www/html/wp-includes dist_tmp/wp-includes' | |
- name: Push the docker image | |
run: docker push $IMAGE | |
- name: Deploy to Cloud Run | |
run: | | |
gcloud run deploy wp \ | |
--image $IMAGE \ | |
--project $GCP_PROJECT \ | |
--platform managed \ | |
--region $GCP_REGION \ | |
--quiet | |
- name: Deploy to Firebase | |
uses: w9jds/firebase-action@master | |
with: | |
args: deploy --only hosting | |
env: | |
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} | |
report-deploy-status: | |
if: always() | |
needs: [delivery] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: technote-space/workflow-conclusion-action@v3 | |
- name: Report deployment status | |
uses: bobheadxi/[email protected] | |
with: | |
step: finish | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: production | |
env_url: https://example.com | |
status: ${{ env.WORKFLOW_CONCLUSION }} | |
deployment_id: ${{ github.event.deployment.id }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment