-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
59 lines (55 loc) · 1.94 KB
/
azure-pipelines.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
# Docker
# Build a Docker image
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- master
resources:
- repo: self
variables:
tag: '$(Build.BuildId)'
stages:
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
- task: Bash@3
inputs:
targetType: 'inline'
script: |
terraform init -input=false
terraform apply -input=false -auto-approve
json_url=$(terraform output -json test_terraform_output_url)
echo "##vso[task.setvariable variable=json_url]$json_url"
ECS_CLUSTER=$(terraform output ecs-cluster)
echo "##vso[task.setvariable variable=ECS_CLUSTER]$ECS_CLUSTER"
ECS_SERVICE=$(terraform output ecs-service)
echo "##vso[task.setvariable variable=ECS_SERVICE]$ECS_SERVICE"
# - task: Docker@2
# displayName: Build an image
# inputs:
# command: build
# Dockerfile: '**/Dockerfile'
# tags: 'aws_terraform'
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
$docker_repo_url = $(json_url).Split("/")[0]
$docker_repo_name = $(json_url).Split("/")[1]
aws ecr get-login-password --region $(TF_VAR_AWS_DEFAULT_REGION) | docker login --username AWS --password-stdin $docker_repo_url
docker build -t "$docker_repo_name" .
docker tag "$docker_repo_name" "$(json_url)":latest
docker push "$(json_url)":latest
aws ecs update-service --region $(TF_VAR_AWS_DEFAULT_REGION) --cluster $(ECS_CLUSTER) --service $(ECS_SERVICE) --force-new-deployment