-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
version: 0.2 | ||
|
||
env: | ||
variables: | ||
_PROJECT_NAME: "gateway" | ||
|
||
phases: | ||
install: | ||
runtime-versions: | ||
java: openjdk8 | ||
docker: 18 | ||
commands: | ||
- echo install kubectl | ||
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl | ||
- chmod +x ./kubectl | ||
- mv ./kubectl /usr/local/bin/kubectl | ||
pre_build: | ||
commands: | ||
- echo Logging in to Amazon ECR... | ||
- echo $_PROJECT_NAME | ||
- echo $AWS_ACCOUNT_ID | ||
- echo $AWS_DEFAULT_REGION | ||
- echo $CODEBUILD_RESOLVED_SOURCE_VERSION | ||
- echo start command | ||
- $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION) | ||
build: | ||
commands: | ||
- echo Build started on `date` | ||
- echo Building the Docker image... | ||
- mvn package -Dmaven.test.skip=true | ||
- docker build -t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$_PROJECT_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION . | ||
post_build: | ||
commands: | ||
- echo Pushing the Docker image... | ||
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$_PROJECT_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION | ||
- echo connect kubectl | ||
- kubectl config set-cluster k8s --server="$KUBE_URL" --insecure-skip-tls-verify=true | ||
- kubectl config set-credentials admin --token="$KUBE_TOKEN" | ||
- kubectl config set-context default --cluster=k8s --user=admin | ||
- kubectl config use-context default | ||
- | | ||
cat <<EOF | kubectl apply -f - | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: $_PROJECT_NAME | ||
labels: | ||
app: $_PROJECT_NAME | ||
spec: | ||
ports: | ||
- port: 8080 | ||
targetPort: 8080 | ||
selector: | ||
app: $_PROJECT_NAME | ||
type: | ||
LoadBalancer | ||
EOF | ||
- | | ||
cat <<EOF | kubectl apply -f - | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: $_PROJECT_NAME | ||
labels: | ||
app: $_PROJECT_NAME | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: $_PROJECT_NAME | ||
template: | ||
metadata: | ||
labels: | ||
app: $_PROJECT_NAME | ||
spec: | ||
containers: | ||
- name: $_PROJECT_NAME | ||
image: $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$_PROJECT_NAME:$CODEBUILD_RESOLVED_SOURCE_VERSION | ||
ports: | ||
- containerPort: 8080 | ||
readinessProbe: | ||
httpGet: | ||
path: /actuator/health | ||
port: 8080 | ||
initialDelaySeconds: 10 | ||
timeoutSeconds: 2 | ||
periodSeconds: 5 | ||
failureThreshold: 10 | ||
livenessProbe: | ||
httpGet: | ||
path: /actuator/health | ||
port: 8080 | ||
initialDelaySeconds: 120 | ||
timeoutSeconds: 2 | ||
periodSeconds: 5 | ||
failureThreshold: 5 | ||
EOF | ||
cache: | ||
paths: | ||
- '/root/.m2/**/*' |