-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract build/deploy into actions reusable by both test/prod pipelines
- Loading branch information
Showing
4 changed files
with
107 additions
and
103 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: build-action | ||
|
||
inputs: | ||
registry_username: | ||
required: true | ||
registry_password: | ||
required: true | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Check if commit already pushed to registry | ||
id: check_registry | ||
shell: bash | ||
run: | | ||
python3 -c " | ||
import sys | ||
import urllib.request | ||
import json | ||
import base64 | ||
with urllib.request.urlopen('https://ghcr.io/token?scope=repository:wappuradio/webbi:pull') as f: | ||
token = json.load(f)['token'] | ||
req = urllib.request.Request( | ||
'https://ghcr.io/v2/wappuradio/webbi/tags/list', | ||
headers={'Authorization': f'Bearer {token}'} | ||
) | ||
with urllib.request.urlopen(req) as f: | ||
if sys.argv[1] in json.load(f)['tags']: | ||
print('exists=true') | ||
else: | ||
print('exists=false')" \ | ||
\ | ||
"${{ github.sha }}" \ | ||
>> $GITHUB_OUTPUT | ||
- name: Log in to registry | ||
if: steps.check_registry.outputs.exists == 'false' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ inputs.registry_username }} | ||
password: ${{ inputs.registry_password }} | ||
|
||
- name: Build and push | ||
if: steps.check_registry.outputs.exists == 'false' | ||
id: docker | ||
uses: docker/build-push-action@v5 | ||
with: | ||
push: true | ||
tags: | | ||
ghcr.io/wappuradio/webbi:${{ github.ref_name }} | ||
ghcr.io/wappuradio/webbi:${{ github.sha }} | ||
outputs: | ||
image: | ||
value: ghcr.io/wappuradio/webbi:${{ github.sha }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: deploy-action | ||
|
||
inputs: | ||
kubeconfig: | ||
required: true | ||
image: | ||
required: true | ||
env: | ||
required: true | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- uses: tale/kubectl-action@v1 | ||
with: | ||
base64-kube-config: "${{ inputs.kubeconfig }}" | ||
|
||
- name: Apply deployment.yaml | ||
shell: bash | ||
run: cat deployment.yaml | sed 's;IMAGE;${{ inputs.image }};' | sed 's/ENV/${{ inputs.env }}/' | kubectl apply -n webbi-${{ inputs.env }} -f - |
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
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