Update .gitea/workflows/dockerK3s.yaml
Some checks failed
Build, Publish Docker Image, and Deploy to Kubernetes / build_and_push (push) Successful in 2s
Build, Publish Docker Image, and Deploy to Kubernetes / deploy_to_k8s (push) Failing after 2s

This commit is contained in:
jonas 2025-03-13 11:21:06 +00:00
parent 6efdfaf957
commit 61cb7b5c7b

View File

@ -7,14 +7,12 @@ on:
workflow_dispatch: workflow_dispatch:
jobs: jobs:
build_and_push_and_deploy: build_and_push:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# Step 1: Checkout repository
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
# Step 2: Check if Dockerfile exists
- name: Check if Dockerfile exists - name: Check if Dockerfile exists
id: check_dockerfile id: check_dockerfile
run: | run: |
@ -24,46 +22,47 @@ jobs:
echo "exists=false" >> $GITHUB_ENV echo "exists=false" >> $GITHUB_ENV
fi fi
# Step 3: Set repository name as image name
- name: Set repository name as image name - name: Set repository name as image name
if: env.exists == 'true' if: env.exists == 'true'
run: echo "IMAGE_NAME=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV run: echo "IMAGE_NAME=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
# Step 4: Log in to Docker registry
- name: Log in to Docker registry - name: Log in to Docker registry
if: env.exists == 'true' if: env.exists == 'true'
run: | run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login git.ionas999.at -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login git.ionas999.at -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin
# Step 5: Build Docker image
- name: Build Docker image - name: Build Docker image
if: env.exists == 'true' if: env.exists == 'true'
run: | run: |
docker build -t git.ionas999.at/${{ env.IMAGE_NAME }}:latest . docker build -t git.ionas999.at/${{ env.IMAGE_NAME }}:latest .
# Step 6: Push Docker image
- name: Push Docker image - name: Push Docker image
if: env.exists == 'true' if: env.exists == 'true'
run: | run: |
docker push git.ionas999.at/${{ env.IMAGE_NAME }}:latest docker push git.ionas999.at/${{ env.IMAGE_NAME }}:latest
# Step 7: Install kubectl deploy_to_k8s:
runs-on: ubuntu-latest
needs: build_and_push
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install kubectl - name: Install kubectl
run: | run: |
# Fetch the latest stable version of kubectl
KUBECTL_VERSION=$(curl -s https://dl.k8s.io/release/stable.txt) KUBECTL_VERSION=$(curl -s https://dl.k8s.io/release/stable.txt)
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl" curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
chmod +x kubectl chmod +x kubectl
sudo mv kubectl /usr/local/bin/ sudo mv kubectl /usr/local/bin/
kubectl version --client kubectl version --client
# Step 8: Configure kubectl using K3s config - name: Configure kubectl using K3s config
- name: Configure kubectl
run: | run: |
mkdir -p ~/.kube mkdir -p ~/.kube
echo "${{ secrets.K3S_CONFIG }}" > ~/.kube/config echo "${{ secrets.K3S_CONFIG }}" > ~/.kube/config
# Step 9: Generate Kubernetes Deployment and Ingress configuration - name: Generate and Apply K3s Deployment and Ingress
- name: Create Kubernetes Deployment and Ingress
run: | run: |
cat > k3s_deployment.yaml <<EOF cat > k3s_deployment.yaml <<EOF
apiVersion: apps/v1 apiVersion: apps/v1
@ -127,7 +126,4 @@ spec:
number: 80 number: 80
EOF EOF
# Step 10: Apply Kubernetes resources
- name: Apply Kubernetes configuration
run: |
kubectl apply -f k3s_deployment.yaml kubectl apply -f k3s_deployment.yaml