Last active
December 22, 2021 08:59
-
-
Save soderlind/0be9a3a06facf3a8a4e01431223d2500 to your computer and use it in GitHub Desktop.
GitHub Action: Deploy WordPress to Azure Container Registry
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: Development deploy | |
on: | |
repository_dispatch: | |
types: trigger-development-deploy | |
workflow_dispatch: | |
push: | |
branches: | |
- develop | |
jobs: | |
# Setup dependencies and fetch packages used by the project. | |
setup: | |
name: Deploy to develop | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the source, this is always the first step. | |
- name: Checkout source | |
uses: actions/checkout@v2 | |
# Set up PHP to our liking for use with WordPress, and to match the live environment. | |
- name: Setup PHP environment | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '7.4' | |
tools: composer:v2 | |
extensions: gd, zip | |
# Print all used versions, handy when debugging. | |
- name: Versions | |
run: | | |
php --version | |
node --version | |
npm --version | |
composer --version | |
# Create cache locations that work across action containers to speed up testing if and when possible. | |
- name: Cache composer dependencies | |
uses: actions/cache@v1 | |
with: | |
path: ~/.composer/cache | |
key: dependencies-composer-${{ hashFiles('composer.lock') }} | |
- name: Cache node dependencies | |
uses: actions/cache@v1 | |
with: | |
path: ~/.npm | |
key: dependencies-composer-${{ hashFiles('package-lock.json') }} | |
# Setup SSH keys for accessing private repositories | |
- name: SSH Key configuration | |
uses: webfactory/ssh-agent@v0.4.1 | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
# If the project includes any composer dependencies, install them now. | |
- name: Conditionally setting up composer | |
working-directory: ./ | |
env: | |
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} | |
run: '(test ! -f composer.json && echo No composer file found.) || composer validate && composer install --no-dev --no-progress && composer run get-translations' | |
# If the project includes any node packages, install them now. | |
- name: Conditionally setting up NPM | |
working-directory: ./ | |
run: '(test ! -f packages.json && echo No packages file found.) || npm install' | |
# Cleanup removes files not wanted in the final production build. | |
- name: Remove unwanted files | |
working-directory: ./ | |
run: | | |
rm -rf .github/ | |
rm -rf .dependabot/ | |
rm -rf tests/ | |
rm -rf .env.example | |
rm -rf .gitignore | |
rm -rf documentation/ | |
# Build and deploy the docker image. | |
- name: Docker login | |
uses: azure/docker-login@v1 | |
with: | |
login-server: ${{ secrets.AZ_REGISTRY_LOGIN_SERVER }} | |
username: ${{ secrets.AZ_REGISTRY_USERNAME }} | |
password: ${{ secrets.AZ_REGISTRY_PASSWORD }} | |
- name: Docker build and push | |
working-directory: ./ | |
run: | | |
docker build . -t OWNER/NAME | |
docker tag OWNER/NAME ${{ secrets.AZ_REGISTRY_LOGIN_SERVER }}/OWNER/NAME | |
docker push ${{ secrets.AZ_REGISTRY_LOGIN_SERVER }}/OWNER/NAME:latest |
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: Latest release | |
on: | |
release: | |
types: [published] | |
jobs: | |
# Setup dependencies and fetch packages used by the project. | |
setup: | |
name: Deploy stable tag | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the source, this is always the first step. | |
- name: Checkout source | |
uses: actions/checkout@v2 | |
# Set up PHP to our liking for use with WordPress, and to match the live environment. | |
- name: Setup PHP environment | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '7.4' | |
tools: composer:v2 | |
extensions: gd, zip | |
# Print all used versions, handy when debugging. | |
- name: Versions | |
run: | | |
php --version | |
node --version | |
npm --version | |
composer --version | |
# Create cache locations that work across action containers to speed up testing if and when possible. | |
- name: Cache composer dependencies | |
uses: actions/cache@v1 | |
with: | |
path: ~/.composer/cache | |
key: dependencies-composer-${{ hashFiles('composer.lock') }} | |
- name: Cache node dependencies | |
uses: actions/cache@v1 | |
with: | |
path: ~/.npm | |
key: dependencies-composer-${{ hashFiles('package-lock.json') }} | |
# Setup SSH keys for accessing private repositories | |
- name: SSH Key configuration | |
uses: webfactory/ssh-agent@v0.4.1 | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
# If the project includes any composer dependencies, install them now. | |
- name: Conditionally setting up composer | |
working-directory: ./ | |
env: | |
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} | |
run: '(test ! -f composer.json && echo No composer file found.) || composer validate && composer install --no-dev --no-progress && composer run get-translations' | |
# If the project includes any node packages, install them now. | |
- name: Conditionally setting up NPM | |
working-directory: ./ | |
run: '(test ! -f packages.json && echo No packages file found.) || npm install' | |
# Cleanup removes files not wanted in the final production build. | |
- name: Remove unwanted files | |
working-directory: ./ | |
run: | | |
rm -rf .github/ | |
rm -rf .dependabot/ | |
rm -rf tests/ | |
rm -rf .env.example | |
rm -rf .gitignore | |
rm -rf documentation/ | |
# Build and deploy the docker image to STAGE. | |
- name: Docker login | |
uses: azure/docker-login@v1 | |
with: | |
login-server: ${{ secrets.AZ_STAGE_REGISTRY_LOGIN_SERVER }} | |
username: ${{ secrets.AZ_STAGE_REGISTRY_USERNAME }} | |
password: ${{ secrets.AZ_STAGE_REGISTRY_PASSWORD }} | |
- name: Docker build and push | |
working-directory: ./ | |
run: | | |
docker build . -t OWNER/NAME | |
docker tag OWNER/NAME ${{ secrets.AZ_STAGE_REGISTRY_LOGIN_SERVER }}/OWNER/NAME:${{ github.event.release.tag_name }} | |
docker push ${{ secrets.AZ_STAGE_REGISTRY_LOGIN_SERVER }}/OWNER/NAME:${{ github.event.release.tag_name }} | |
# Build and deploy the docker image to PROD. | |
- name: Docker login | |
uses: azure/docker-login@v1 | |
with: | |
login-server: ${{ secrets.AZ_PROD_REGISTRY_LOGIN_SERVER }} | |
username: ${{ secrets.AZ_PROD_REGISTRY_USERNAME }} | |
password: ${{ secrets.AZ_PROD_REGISTRY_PASSWORD }} | |
- name: Docker build and push | |
working-directory: ./ | |
run: | | |
docker tag OWNER/NAME ${{ secrets.AZ_PROD_REGISTRY_LOGIN_SERVER }}/OWNER/NAME:${{ github.event.release.tag_name }} | |
docker push ${{ secrets.AZ_PROD_REGISTRY_LOGIN_SERVER }}/OWNER/NAME:${{ github.event.release.tag_name }} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment