-
-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (132 loc) · 5.43 KB
/
publish-containerimage.yml
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
name: Publish / Mastodon container images
on:
# Run every Monday at 12:00 EDT (16:00 UTC)
schedule:
- cron: "0 16 * * MON"
# Allow manual trigger
workflow_dispatch:
inputs:
delete_layer_cache:
type: boolean
description: Delete the layer cache generated by previous builds.
default: false
do_not_rebuild_os:
type: boolean
description: Do not rebuild the OS.
default: false
do_not_rebuild_mastodon:
type: boolean
description: Do not rebuild Mastodon.
default: false
permissions:
actions: write
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 'Checkout: Latest commit'
uses: actions/checkout@v4
with:
submodules: true
- name: Get current ticks
id: get_current_ticks
shell: pwsh
run: |
$currentDateTimeTicks = [System.DateTimeOffset]::Now.UtcTicks
"current_datetime_ticks=$($currentDateTimeTicks)" >> $env:GITHUB_ENV
# Clear the layer cache if the 'delete_layer_cache' input is true.
- name: Clear layer cache
if: ${{ inputs.delete_layer_cache == true }}
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
gh extension install actions/gh-actions-cache
$cacheList = gh actions-cache list --branch "main"
$cacheKeys = ($cacheList | Select-String -Pattern "^(?'cacheKey'.+?)\t.+$").Matches | ForEach-Object { $PSItem.Groups["cacheKey"].Value }
$cacheKeys | ForEach-Object { gh actions-cache delete "$($PSItem)" --confirm }
# Cache the current seed for building the OS.
- name: Cache OS build seed
id: cache_os_build_seed
uses: actions/cache@v3
with:
path: ./.os-build-seed
key: ${{ runner.os }}-os-build-seed
# Cache the current seed for building Mastodon.
- name: Cache Mastodon build seed
id: cache_mastodon_build_seed
uses: actions/cache@v3
with:
path: ./.build-seed
key: ${{ runner.os }}-build-seed
# Generate a new seed for building the OS if:
# - No seed was previously cached
# - The workflow is triggered by a schedule
# - The workflow is triggered by a manual trigger and the 'do_not_rebuild_os' input is false
- name: Generate OS build seed
id: generate_os_build_seed
if: ${{ steps.cache_os_build_seed.outputs.cache-hit != 'true' || github.event_name == 'schedule' || inputs.do_not_rebuild_os == false }}
shell: pwsh
run: |
$buildSeed = (New-Guid).Guid
$buildSeed > ./.os-build-seed
# Generate a new seed for building Mastodon if:
# - No seed was previously cached
# - The workflow is triggered by a schedule
# - The workflow is triggered by a manual trigger and the 'do_not_rebuild_os' input is false
# - The workflow is triggered by a manual trigger and the 'do_not_rebuild_mastodon' input is false
- name: Generate Mastodon build seed
id: generate_build_seed
if: ${{ steps.cache_mastodon_build_seed.outputs.cache-hit != 'true' || github.event_name == 'schedule' || inputs.do_not_rebuild_os == false || inputs.do_not_rebuild_mastodon == false }}
shell: pwsh
run: |
$buildSeed = (New-Guid).Guid
$buildSeed > ./.build-seed
# Set the build seed environment variables.
- name: Set build seed environment variables
shell: pwsh
run: |
$mastodonBuildSeed = Get-Content -Path "./.build-seed" -Raw
"build_seed=$($mastodonBuildSeed)" >> $env:GITHUB_ENV
$osBuildSeed = Get-Content -Path "./.os-build-seed" -Raw
"os_build_seed=$($osBuildSeed)" >> $env:GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into Azure container registry
uses: docker/login-action@v3
with:
registry: smallsonlinemstdncontainers.azurecr.io
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Log into GitHub container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
smallsonlinemstdncontainers.azurecr.io/ocwsocial-glitch-soc
ghcr.io/${{ github.repository_owner }}/ocw-social-mastodon
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=schedule,pattern={{date 'YYYYMMDD-hhmmss' tz='UTC'}}
type=ref,event=branch
type=sha
- name: Build and push container image to registry
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
build-args: |
OS_BUILD_SEED=${{ env.os_build_seed }}
BUILD_SEED=${{ env.build_seed }}
platforms: linux/amd64
cache-from: type=gha
cache-to: type=gha,mode=max