Created
January 31, 2020 15:27
-
-
Save bdelafaire/5d626fee9282325c4223527dcf8ff2b3 to your computer and use it in GitHub Desktop.
Maven Build/Deploy on GKE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Maven projet and deploy on Kube | |
on: [push, pull_request] | |
env: | |
GKE_PROJECT: ${{ secrets.GKE_PROJECT }} | |
GKE_CLUSTER: java-hello-world-cluster | |
GKE_ZONE: us-central1-f | |
IMAGE: java-hello-world | |
jobs: | |
compile: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
java: [ 11 ] | |
name: Java ${{ matrix.java }} compile | |
steps: | |
- uses: actions/checkout@master | |
- name: Setup java | |
uses: actions/setup-java@v1 | |
with: | |
java-version: ${{ matrix.java }} | |
- run: mvn -f pom.xml clean compile | |
build: | |
runs-on: ubuntu-latest | |
needs: compile | |
name: Build Maven project | |
steps: | |
- uses: actions/checkout@v1 | |
- uses: actions/cache@v1 | |
with: | |
path: ~/.m2/repository | |
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
restore-keys: | | |
${{ runner.os }}-maven- | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 11 | |
- name: Build and test project | |
run: mvn -f pom.xml clean verify | |
- name: Upload Maven build artifact | |
uses: actions/upload-artifact@v1 | |
with: | |
name: artifact | |
path: target/java-hello-world-1.0-SNAPSHOT.jar | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
name: Build Docker container and deploy to Kubernetes | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Download Maven build artifact | |
uses: actions/download-artifact@v1 | |
with: | |
name: artifact | |
- name: Build Docker container | |
run: | | |
mkdir -p java-hello-world/target | |
mv artifact/java-hello-world-1.0-SNAPSHOT.jar java-hello-world/target | |
docker build -t java-hello-world . --tag gcr.io/$GKE_PROJECT/$IMAGE | |
- name: install python-openssl | |
run: sudo apt-get install -y python-openssl -o=Dpkg::Use-Pty=0 | |
- name: Setup gcloud environment | |
uses: GoogleCloudPlatform/[email protected] | |
with: | |
service_account_key: ${{ secrets.GCP_SA_KEY }} | |
- run: | | |
gcloud auth configure-docker | |
- name: Publish | |
run: | | |
docker push gcr.io/$GKE_PROJECT/$IMAGE | |
- name: Set up Kustomize | |
run: | | |
curl -o kustomize --location https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64 | |
chmod u+x ./kustomize | |
- name: Deploy | |
run: | | |
gcloud container clusters get-credentials $GKE_CLUSTER --zone $GKE_ZONE --project $GKE_PROJECT | |
./kustomize edit set image gcr.io/GKE_PROJECT/IMAGE=gcr.io/$GKE_PROJECT/$IMAGE | |
./kustomize build . | kubectl apply -f - | |
kubectl get services -o wide |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment