-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (150 loc) · 6.01 KB
/
deploy.yaml
File metadata and controls
163 lines (150 loc) · 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
---
name: Deploy
# yamllint disable-line rule:truthy
on:
release:
types:
- published
workflow_run:
workflows: ["CI"]
branches: [main]
types:
- completed
jobs:
information:
if: |
github.event_name == 'release'
|| (
github.event_name == 'workflow_run'
&& github.event.workflow_run.conclusion == 'success'
)
name: ℹ️ Gather add-on information
runs-on: ubuntu-latest
outputs:
containersha: ${{ steps.information.outputs.containersha }}
description: ${{ steps.information.outputs.description }}
environment: ${{ steps.information.outputs.environment }}
name: ${{ steps.information.outputs.name }}
version: ${{ steps.information.outputs.version }}
wordpress_version: ${{ steps.information.outputs.wordpress-version }}
build_date: ${{ steps.information.outputs.build_date }}
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v3
- name: ℹ️ Gather version and environment
id: information
# yamllint disable rule:line-length
run: |
sha="${{ github.sha }}"
environment="edge"
version="${sha:0:7}"
wordpress_version="$(curl -s GET https://api.github.com/repos/WordPress/WordPress/tags\?per_page\=1 | jq -r '.[].name')"
echo "::set-output name=containersha::${version}"
if [[ "${{ github.event_name }}" = "release" ]]; then
version="${{ github.event.release.tag_name }}"
version="${version,,}"
version="${version#v}"
environment="stable"
if [[ "${{ github.event.release.prerelease }}" = "true" ]]; then
environment="beta"
fi
fi
echo "::set-output name=wordpress-version::${wordpress_version}"
echo "::set-output name=environment::${environment}"
echo "::set-output name=version::${version}"
echo "::set-output name=name::Wordpress ${wordpress_version}"
echo "::set-output name=description::Wordpress ${wordpress_version} in a container that works"
# yamllint enable rule:line-length
deploy:
name: 👷 Build & Deploy
needs:
- information
runs-on: ubuntu-latest
steps:
- name: ⤵️ Check out code from GitHub
uses: actions/checkout@v3
- name: Install Latest Docker
# yamllint disable rule:line-length
run: |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce
# yamllint enable rule:line-length
- name: 📝 Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
aperimau/wordpress
ghcr.io/aperim/wordpress
# generate Docker tags based on the following events/attributes
# yamllint disable rule:line-length
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,prefix=wordpress-,value=${{ needs.information.outputs.wordpress_version }},enable=${{ github.event.release.tag_name != '' }}
type=sha
# yamllint enable rule:line-length
- name: 🏗 Set up build cache
id: cache
uses: actions/cache@v3.0.11
with:
path: /tmp/.buildx-cache
# Key is named differently to avoid collision
key: ${{ runner.os }}-multi-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-multi-buildx
- name: 🏗 Set up QEMU
uses: docker/setup-qemu-action@v2
- name: 🏗 Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: 🏗 Login to Docker Container Registry
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: 🏗 Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CI_PAT }}
- name: 🚀 Build
uses: docker/build-push-action@v3
with:
push: true
builder: ${{ steps.buildx.outputs.name }}
context: ./wordpress
file: ./wordpress/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
# yamllint disable-line rule:line-length
# platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64/v8
# yamllint disable-line rule:line-length
platforms: linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64/v8
build-args: |
WORDPRESS_VERSION=${{ needs.information.outputs.wordpress_version }}
BUILD_DATE=${{ steps.flags.outputs.date }}
BUILD_DESCRIPTION=${{ needs.information.outputs.description }}
BUILD_NAME=${{ needs.information.outputs.name }}
BUILD_REF=${{ github.sha }}
BUILD_REPOSITORY=${{ github.repository }}
BUILD_VERSION=${{ needs.information.outputs.version }}
# This ugly bit is necessary, or our cache will grow forever...
# Well until we hit GitHub's limit of 5GB :)
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: 🚚 Swap build cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache