diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..4d28ef3 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,50 @@ +name: Build Container Image + +on: + workflow_dispatch: + inputs: + tag: + description: 'Image tag' + required: false + default: 'latest' + type: string + +env: + REGISTRY: ${{ secrets.CONTAINER_REGISTRY }} + IMAGE_NAME: ${{ secrets.IMAGE_NAME }} + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=${{ inputs.tag }} + type=sha,prefix={{branch}}- + + - 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: Output image tags + run: | + echo "Built and pushed image tags: ${{ steps.meta.outputs.tags }}" \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..6ff1361 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,123 @@ +name: Deploy to Kubernetes + +on: + workflow_dispatch: + inputs: + image_tag: + description: 'Docker image tag to deploy' + required: true + default: 'latest' + type: string + environment: + description: 'Deployment environment' + required: false + default: 'production' + type: string + +env: + REGISTRY: ${{ secrets.CONTAINER_REGISTRY }} + IMAGE_NAME: ${{ secrets.IMAGE_NAME }} + APP_NAME: ${{ secrets.APP_NAME }} + HOST: ${{ secrets.HOST }} + NAMESPACE: ${{ secrets.K8S_NAMESPACE }} + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup kubectl + uses: azure/setup-kubectl@v3 + with: + version: 'v1.28.0' + + - name: Configure kubectl + run: | + echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 -d > kubeconfig + export KUBECONFIG=kubeconfig + kubectl config current-context + + - name: Create namespace if not exists + run: | + export KUBECONFIG=kubeconfig + kubectl create namespace ${{ env.NAMESPACE }} --dry-run=client -o yaml | kubectl apply -f - + + - name: Deploy to Kubernetes + run: | + export KUBECONFIG=kubeconfig + + # Create deployment + cat <