Fix KUBECONFIG path in GitHub Actions
This commit is contained in:
parent
45042b7e47
commit
761058e607
1 changed files with 12 additions and 20 deletions
32
.github/workflows/build-and-deploy.yaml
vendored
32
.github/workflows/build-and-deploy.yaml
vendored
|
|
@ -12,17 +12,12 @@ jobs:
|
||||||
packages: write
|
packages: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# Step 1: Checkout the repository code
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# Step 2: Debug repository information (optional)
|
- name: Debug repository name
|
||||||
- name: Debug Repository Info
|
run: echo "Repository: ${{ github.repository }}"
|
||||||
run: |
|
|
||||||
echo "Repository: ${{ github.repository }}"
|
|
||||||
echo "Actor: ${{ github.actor }}"
|
|
||||||
|
|
||||||
# Step 3: Log in to GitHub Container Registry
|
|
||||||
- name: Log in to GitHub Container Registry
|
- name: Log in to GitHub Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
|
|
@ -30,28 +25,25 @@ jobs:
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
# Step 4: Build and Push Docker Image with unique tag
|
|
||||||
- name: Build and Push Docker Image
|
- name: Build and Push Docker Image
|
||||||
run: |
|
run: |
|
||||||
IMAGE_NAME="ghcr.io/${{ github.repository }}"
|
IMAGE_NAME="ghcr.io/${{ github.repository }}"
|
||||||
TAG="${{ github.sha }}"
|
docker build -t "$IMAGE_NAME:latest" .
|
||||||
docker build -t "$IMAGE_NAME:$TAG" .
|
docker push "$IMAGE_NAME:latest"
|
||||||
docker push "$IMAGE_NAME:$TAG"
|
shell: bash
|
||||||
|
|
||||||
# Step 5: Set up kubeconfig for Kubernetes access
|
- name: Set up Kubeconfig
|
||||||
- name: Set up kubeconfig
|
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.kube
|
mkdir -p ~/.kube
|
||||||
echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > ~/.kube/config
|
echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > ~/.kube/config
|
||||||
chmod 600 ~/.kube/config
|
chmod 600 ~/.kube/config
|
||||||
env:
|
export KUBECONFIG=~/.kube/config
|
||||||
KUBECONFIG: ~/.kube/config
|
kubectl version --short
|
||||||
|
shell: bash
|
||||||
|
|
||||||
# Step 6: Deploy the Docker image to Kubernetes
|
|
||||||
- name: Deploy to Kubernetes
|
- name: Deploy to Kubernetes
|
||||||
run: |
|
run: |
|
||||||
|
export KUBECONFIG=~/.kube/config
|
||||||
IMAGE_NAME="ghcr.io/${{ github.repository }}"
|
IMAGE_NAME="ghcr.io/${{ github.repository }}"
|
||||||
TAG="${{ github.sha }}"
|
kubectl set image deployment/homepage homepage=$IMAGE_NAME:latest -n web
|
||||||
kubectl set image deployment/homepage homepage=$IMAGE_NAME:$TAG -n web
|
shell: bash
|
||||||
env:
|
|
||||||
KUBECONFIG: ~/.kube/config
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue