diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000..dc8b880 --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,69 @@ +name: main-worklfow +on: + workflow_dispatch: + push: + branches: + - master + - awesome-feature + pull_request: + branches: + - master + - awesome-feature +env: + IMAGE_REPOSITORY: ghcr.io/paez1999/foobar +jobs: + # Run all unit tests. + run-tests: + runs-on: ubuntu-latest + steps: + # Check out the pull request's source code. + - name: Check out source code + uses: actions/checkout@v3 + # Install Go. + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: "^1.14" + - name: Print Go version + run: go version + # Run unit tests. + - name: Run unit tests + run: go test -v ./... + + # Build and release. + build-and-release: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Check out source code + uses: actions/checkout@v3 + - name: Build and push container image + uses: docker/build-push-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ env.IMAGE_REPOSITORY }} + tag_with_ref: true + tag_with_sha: true + + # Deploy to Kubernetes. + deploy: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/master' + needs: + - run-tests + - build-and-release + steps: + - uses: actions/checkout@v3 + - name: Configure kubectl + run: echo ${{ secrets.KUBECONFIG }} | base64 -d > kubeconfig.yml + - name: Kustomize image + working-directory: ./manifests + run: kustomize edit set image REPOSITORY:TAG=$IMAGE_REPOSITORY:sha-${GITHUB_SHA::7} + - name: Deploy to Kubernetes + run: kubectl --kubeconfig kubeconfig.yml apply --kustomize manifests/ + - name: Validate deployment + run: kubectl --kubeconfig kubeconfig.yml rollout status --timeout 120s deployment/foobar