test #4
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: Deploy | |
on: | |
push: | |
branches: | |
- main | |
- demos-on-gh | |
workflow_dispatch: | |
env: | |
IMAGE_NAME: ghcr.io/${{ github.repository }} | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Log in to GHCR | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Extract metadata (tags, labels) | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.IMAGE_NAME }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Log out of GHCR | |
run: docker logout ghcr.io | |
deploy: | |
runs-on: [self-hosted, self-hosted-linux-amd64-jammy-private-endpoint-medium] | |
needs: build-and-push | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install dependencies | |
run: | | |
sudo snap install kubectl --classic | |
sudo snap install konf | |
- name: Configure kubectl | |
run: | | |
printf "%s" "${{ secrets.KUBE_CONFIG }}" > kubeconfig | |
export KUBECONFIG=kubeconfig | |
- name: Deploy application | |
run: | | |
export KUBECONFIG=kubeconfig | |
cat kubeconfig | |
epoch_time=$(date +%s) | |
image_tag="${epoch_time}-${GITHUB_SHA::7}" | |
image_name="${{ env.IMAGE_NAME }}:${image_tag}" | |
echo "Deploying image: $image_name" | |
konf staging konf/site.yaml --tag $image_tag | kubectl apply -f - | |
kubectl rollout status deployment jaas-ai --namespace=staging | |
echo "Deployment successful!" | |
- name: Clean up | |
run: | | |
rm kubeconfig |