diff --git a/.github/workflows/.trigger-test b/.github/workflows/.trigger-test new file mode 100644 index 0000000..e69de29 diff --git a/.github/workflows/build-and-deploy.yaml b/.github/workflows/build-and-deploy.yaml index ba59027..0766bfd 100644 --- a/.github/workflows/build-and-deploy.yaml +++ b/.github/workflows/build-and-deploy.yaml @@ -1,54 +1,48 @@ -name: Build and Deploy to Kubernetes +name: Build and Deploy on: push: - branches: [ main ] + branches: + - main + - dev + - 'feat/**' + - 'test/**' + - 'fix/**' + - 'hotfix/**' + +env: + VERSION: ${{ vars.VERSION || 'latest' }} + NAMESPACE: ${{ github.ref == 'refs/heads/main' && 'prod' || 'web' }} jobs: build-and-deploy: runs-on: ubuntu-latest - permissions: - contents: read - packages: write - env: - KUBECONFIG: ${HOME}/.kube/config steps: - name: Checkout code uses: actions/checkout@v3 - - name: Debug repository name - run: | - echo "Repository: ${{ github.repository }}" - - name: Log in to GitHub Container Registry - uses: docker/login-action@v3 + uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and Push Docker Image + - name: Build and push Docker image run: | - IMAGE_NAME="ghcr.io/${{ github.repository }}" - docker build -t "$IMAGE_NAME:latest" . - docker push "$IMAGE_NAME:latest" - shell: bash + IMAGE_NAME="ghcr.io/${{ github.repository }}:$VERSION" + docker build -t $IMAGE_NAME . + docker push $IMAGE_NAME - - name: Set up Kubeconfig + - name: Set up kubeconfig from secret run: | - mkdir -p ${HOME}/.kube - echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > ${HOME}/.kube/config - chmod 600 ${HOME}/.kube/config - export KUBECONFIG=${HOME}/.kube/config - kubectl version --client - kubectl cluster-info - cat ${HOME}/.kube/config + mkdir -p $HOME/.kube + echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > $HOME/.kube/config shell: bash - name: Deploy to Kubernetes run: | - export KUBECONFIG=${HOME}/.kube/config - IMAGE_NAME="ghcr.io/${{ github.repository }}" - kubectl set image deployment/homepage home=$IMAGE_NAME:v0.0.1 -n web + IMAGE="ghcr.io/${{ github.repository }}:$VERSION" + kubectl set image deployment/homepage home=$IMAGE -n $NAMESPACE shell: bash diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..579be40 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,53 @@ +# .github/workflows/deploy.yaml + +name: Build and Deploy to Kubernetes + +#on: +# push: +# branches: [ main ] + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Debug Variables + run: echo "Repository: ${{ github.repository }}" + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Push Docker Image + run: | + IMAGE_NAME="ghcr.io/${{ github.repository }}" + docker build -t "$IMAGE_NAME:latest" . + docker push "$IMAGE_NAME:latest" + shell: bash + + - name: Set up Kubeconfig + run: | + mkdir -p ~/.kube + echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > ~/.kube/config + chmod 600 ~/.kube/config + + - name: Deploy to Kubernetes + run: | + kubectl set image deployment/homepage homepage=ghcr.io/${{ github.repository }}:latest -n web + + - name: Set up kubeconfig + run: | + mkdir -p ~/.kube + echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > ~/.kube/config + chmod 600 ~/.kube/config + env: + KUBECONFIG: ~/.kube/config diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..25e7b7a --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,40 @@ +name: Build and Push Docker Image + +on: + push: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Push Docker Image + run: | + IMAGE="ghcr.io/${{ github.repository }}" + docker build -t "$IMAGE:latest" . + docker push "$IMAGE:latest" + + - name: Set up Kubeconfig + run: | + mkdir -p ~/.kube + echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > ~/.kube/config + chmod 600 ~/.kube/config + env: + KUBECONFIG: ~/.kube/config + + - name: Deploy to Kubernetes + run: | + IMAGE="ghcr.io/${{ github.repository }}" + kubectl set image deployment/homepage homepage=$IMAGE:latest -n web diff --git a/.trigger-test b/.trigger-test new file mode 100644 index 0000000..bdd5497 --- /dev/null +++ b/.trigger-test @@ -0,0 +1 @@ +# trigger test Fri Apr 11 14:35:35 UTC 2025 diff --git a/trigger-workflow.txt b/trigger-workflow.txt new file mode 100644 index 0000000..e69de29 diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..7df503e --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +v0.0.4