base64 wants bytes, not strings #34
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: ci | |
on: | |
push: | |
branches: | |
- "master" | |
jobs: | |
build: | |
runs-on: actions-runner | |
steps: | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Check if commit already pushed to registry | |
id: check_registry | |
run: | | |
python3 -c " | |
import sys | |
import urllib.request | |
import json | |
import base64 | |
req = urllib.request.Request( | |
'https://ghcr.io/v2/wappuradio/webbi/tags/list', | |
headers={ | |
'Authorization': 'Basic ' + base64.b64encode(sys.argv[1].encode()).decode() | |
} | |
) | |
with urllib.request.urlopen(req) as f: | |
if sys.argv[2] in json.load(f)['tags']: | |
print('exists=true') | |
else: | |
print('exists=false')" \ | |
\ | |
"${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}" \ | |
"${{ github.sha }}" \ | |
>> $GITHUB_OUTPUT | |
- 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: ghcr.io/wappuradio/webbi:${{ github.sha }} | |
deploy: | |
runs-on: actions-runner | |
needs: build | |
environment: | |
name: test | |
url: https://webbi-test.wappuradio.fi | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- uses: tale/kubectl-action@v1 | |
with: | |
base64-kube-config: ${{ secrets.KUBECONFIG_BASE64 }} | |
- run: cat deployment.yaml | sed 's;IMAGE;${{ needs.build.outputs.image }};' | sed 's/ENV/test/' | kubectl apply -n webbi-test -f - |