|
| 1 | +name: Build, Test and Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +jobs: |
| 12 | + |
| 13 | + build-test-and-push: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v2 |
| 17 | + - name: Set up JDK 11 |
| 18 | + uses: actions/setup-java@v2 |
| 19 | + with: |
| 20 | + java-version: 11 |
| 21 | + distribution: adopt |
| 22 | + - name: Docker Login |
| 23 | + uses: Azure/docker-login@v1 |
| 24 | + with: |
| 25 | + username: ${{ secrets.REGISTRY_USERNAME }} |
| 26 | + password: ${{ secrets.REGISTRY_PASSWORD }} |
| 27 | + - name: Build application |
| 28 | + run: mvn -B package jib:dockerBuild |
| 29 | + - name: Build acceptance tests |
| 30 | + run: docker build -t heroes-acceptence-tests heroes-acceptence-tests |
| 31 | + - name: Run app for tests |
| 32 | + run: | |
| 33 | + docker run --name ash -d --rm -p 8080:8080 porscheinformatik/angular-spring-heroes |
| 34 | + sleep 30 |
| 35 | + docker run -i --rm --link ash heroes-acceptence-tests --config baseUrl=http://ash:8080 |
| 36 | + - name: Push image to Docker Hub |
| 37 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 38 | + run: docker push porscheinformatik/angular-spring-heroes |
| 39 | + - name: Push image to ghcr.io |
| 40 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 41 | + run: | |
| 42 | + echo ${{ secrets.GHCR_PASSWORD }} | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin |
| 43 | + docker tag porscheinformatik/angular-spring-heroes ghcr.io/porscheinformatik/angular-spring-heroes |
| 44 | + docker push ghcr.io/porscheinformatik/angular-spring-heroes |
| 45 | +
|
| 46 | + deploy: |
| 47 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 48 | + needs: build-test-and-push |
| 49 | + runs-on: ubuntu-latest |
| 50 | + environment: |
| 51 | + name: production |
| 52 | + url: https://ash.k8s.derkoe.dev |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v2 |
| 55 | + - uses: Azure/setup-helm@v1 |
| 56 | + - name: Deploy to Kubernetes |
| 57 | + run: | |
| 58 | + echo "${{ secrets.KUBECONFIG_BASE64 }}" | base64 --decode > /tmp/kubeconfig |
| 59 | + helm ls --kubeconfig /tmp/kubeconfig |
| 60 | + helm upgrade --kubeconfig /tmp/kubeconfig --install --atomic --set ingress.enabled=true --set ingress.host=ash.k8s.derkoe.dev --set postgresql.enabled=true --set postgresql.postgresPassword=${{ secrets.POSTGRESQL_PASSWORD }} ash charts/angular-spring-heroes |
0 commit comments