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
|
||||
|
||||
steps:
|
||||
# Step 1: Checkout the repository code
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
# Step 2: Debug repository information (optional)
|
||||
- name: Debug Repository Info
|
||||
run: |
|
||||
echo "Repository: ${{ github.repository }}"
|
||||
echo "Actor: ${{ github.actor }}"
|
||||
- name: Debug repository name
|
||||
run: echo "Repository: ${{ github.repository }}"
|
||||
|
||||
# Step 3: Log in to GitHub Container Registry
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
|
|
@ -30,28 +25,25 @@ jobs:
|
|||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# Step 4: Build and Push Docker Image with unique tag
|
||||
- name: Build and Push Docker Image
|
||||
run: |
|
||||
IMAGE_NAME="ghcr.io/${{ github.repository }}"
|
||||
TAG="${{ github.sha }}"
|
||||
docker build -t "$IMAGE_NAME:$TAG" .
|
||||
docker push "$IMAGE_NAME:$TAG"
|
||||
docker build -t "$IMAGE_NAME:latest" .
|
||||
docker push "$IMAGE_NAME:latest"
|
||||
shell: bash
|
||||
|
||||
# Step 5: Set up kubeconfig for Kubernetes access
|
||||
- name: Set up kubeconfig
|
||||
- name: Set up Kubeconfig
|
||||
run: |
|
||||
mkdir -p ~/.kube
|
||||
echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > ~/.kube/config
|
||||
chmod 600 ~/.kube/config
|
||||
env:
|
||||
KUBECONFIG: ~/.kube/config
|
||||
export KUBECONFIG=~/.kube/config
|
||||
kubectl version --short
|
||||
shell: bash
|
||||
|
||||
# Step 6: Deploy the Docker image to Kubernetes
|
||||
- name: Deploy to Kubernetes
|
||||
run: |
|
||||
export KUBECONFIG=~/.kube/config
|
||||
IMAGE_NAME="ghcr.io/${{ github.repository }}"
|
||||
TAG="${{ github.sha }}"
|
||||
kubectl set image deployment/homepage homepage=$IMAGE_NAME:$TAG -n web
|
||||
env:
|
||||
KUBECONFIG: ~/.kube/config
|
||||
kubectl set image deployment/homepage homepage=$IMAGE_NAME:latest -n web
|
||||
shell: bash
|
||||
|
|
|
|||
Loading…
Reference in a new issue