-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy pathbuildspec.yml
91 lines (88 loc) · 3.04 KB
/
buildspec.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
version: 0.2
env:
variables:
_PROJECT_NAME: "ui"
phases:
install:
runtime-versions:
nodejs: 10
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
- npm install
- $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- npm run build
- 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
- _GATEWAY_IP=$(kubectl get -o jsonpath="{.status.loadBalancer.ingress[0].hostname}" svc gateway --ignore-not-found)
- _GATEWAY_PORT=$(kubectl get -o jsonpath="{.spec.ports[0].port}" svc gateway --ignore-not-found)
- |
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
env:
- name: VUE_APP_API_HOST
value: http://${_GATEWAY_IP:-localhost}:${_GATEWAY_PORT:-8080}
EOF
cache:
paths:
- 'node_modules/**/*'