1
+ # build.yml
2
+ on :
3
+ # pull_request:
4
+ # paths:
5
+ # - desci-server/**
6
+ push :
7
+ paths :
8
+ - .github/workflows/**
9
+ - desci-server/**
10
+ - desci-contracts/**
11
+ - Dockerfile
12
+ branches : # array of glob patterns matching against refs/heads. Optional; defaults to all
13
+ - main # triggers on pushes that contain changes
14
+ - develop
15
+
16
+ name : Build automating-metadata
17
+
18
+ # https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html
19
+ env :
20
+ AWS_DEFAULT_REGION : us-east-2
21
+ AWS_DEFAULT_OUTPUT : json
22
+ AWS_ACCOUNT_ID : ${{ secrets.AWS_ACCOUNT_ID }}
23
+ AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY_ID }}
24
+ AWS_SECRET_ACCESS_KEY : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
25
+ CONTAINER_IMAGE : automating-metadata
26
+ DOCKER_BUILDKIT : 1
27
+
28
+ jobs :
29
+ build-and-push-images :
30
+ # we build and push for every commit, even if tests pass, that way when tests pass deployment is short (run test + build in parallel)
31
+ name : Build and push images
32
+ runs-on : ubuntu-latest
33
+ steps :
34
+ - uses : hashicorp/setup-terraform@v1
35
+ - name : Checkout
36
+ uses : actions/checkout@v4
37
+
38
+ # Add steps here like linting, testing, minification, etc.
39
+ - id : install-aws-cli
40
+ uses : unfor19/install-aws-cli-action@v1
41
+ with :
42
+ version : 1
43
+
44
+ - uses : prepor/action-aws-iam-authenticator@master
45
+ - run : aws-iam-authenticator version
46
+
47
+ - name : Install Kubectl
48
+ run : |
49
+ #$(curl -Ls https://dl.k8s.io/release/stable.txt)
50
+ version=v1.23.6
51
+ echo "using kubectl@$version"
52
+ curl -sLO "https://dl.k8s.io/release/$version/bin/linux/amd64/kubectl" -o kubectl
53
+ chmod +x kubectl
54
+ mv kubectl /usr/local/bin
55
+ mkdir $HOME/.kube
56
+ sudo apt-get update
57
+ sudo apt-get install less
58
+ echo ${{ secrets.KUBE_CONFIG_DATA }} | base64 --decode > $HOME/.kube/config
59
+ aws sts get-caller-identity
60
+
61
+ - name : Build and tag the image (DEV)
62
+ if : github.ref == 'refs/heads/develop'
63
+ run : |
64
+ # Build and tag the image
65
+ docker build \
66
+ -t $CONTAINER_IMAGE-dev:${{ github.sha }} \
67
+ -t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev \
68
+ .
69
+
70
+ - name : Build and tag the image (PROD)
71
+ if : github.ref == 'refs/heads/main'
72
+ run : |
73
+ # Build and tag the image
74
+ docker build \
75
+ -t $CONTAINER_IMAGE-prod:${{ github.sha }} \
76
+ -t $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-prod \
77
+ .
78
+
79
+ - name : Push (DEV)
80
+ if : github.ref == 'refs/heads/develop'
81
+ run : |
82
+ # Push image to AWS ECR
83
+ aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
84
+ docker tag $CONTAINER_IMAGE-dev:${{ github.sha }} $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev:${{ github.sha }}
85
+ docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev:${{ github.sha }}
86
+
87
+ - name : Push (PROD)
88
+ if : github.ref == 'refs/heads/main'
89
+ run : |
90
+ # Push image to AWS ECR
91
+ aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
92
+ docker tag $CONTAINER_IMAGE-prod:${{ github.sha }} $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-prod:${{ github.sha }}
93
+ docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-prod:${{ github.sha }}
94
+
95
+ deploy :
96
+ name : Deploy automating-metadata
97
+ needs :
98
+ - build-and-push-images
99
+
100
+ runs-on : ubuntu-latest
101
+ steps :
102
+ - uses : hashicorp/setup-terraform@v1
103
+ - name : Checkout
104
+ uses : actions/checkout@v4
105
+
106
+ # Add steps here like linting, testing, minification, etc.
107
+ - id : install-aws-cli
108
+ uses : unfor19/install-aws-cli-action@v1
109
+ with :
110
+ version : 1
111
+
112
+ - uses : prepor/action-aws-iam-authenticator@master
113
+ - run : aws-iam-authenticator version
114
+
115
+ - name : Install Kubectl
116
+ run : |
117
+ #$(curl -Ls https://dl.k8s.io/release/stable.txt)
118
+ version=v1.23.6
119
+ echo "using kubectl@$version"
120
+ curl -sLO "https://dl.k8s.io/release/$version/bin/linux/amd64/kubectl" -o kubectl
121
+ chmod +x kubectl
122
+ mv kubectl /usr/local/bin
123
+ mkdir $HOME/.kube
124
+ sudo apt-get update
125
+ sudo apt-get install less
126
+ echo ${{ secrets.KUBE_CONFIG_DATA }} | base64 --decode > $HOME/.kube/config
127
+ aws sts get-caller-identity
128
+
129
+ - name : Deploy to EKS (DEV)
130
+ # uses: steebchen/kubectl@v2.0.0
131
+ if : github.ref == 'refs/heads/develop'
132
+ run : | # defaults to latest kubectl binary version
133
+ kubectl apply -f desci-server/kubernetes/deployment_dev.yaml
134
+ kubectl set image deployment/desci-server-dev desci-server-dev=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev:${{ github.sha }} --record
135
+ aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
136
+ docker pull $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev:${{ github.sha }}
137
+ docker tag $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev:${{ github.sha }} $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev:latest
138
+ docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-dev:latest
139
+
140
+ - name : Deploy to EKS (PROD)
141
+ if : github.ref == 'refs/heads/main'
142
+ run : | # defaults to latest kubectl binary version
143
+ kubectl apply -f desci-server/kubernetes/deployment_prod.yaml
144
+ kubectl set image deployment/desci-server desci-server=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-prod:${{ github.sha }} --record
145
+ aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
146
+ docker pull $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-prod:${{ github.sha }}
147
+ docker tag $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-prod:${{ github.sha }} $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-prod:latest
148
+ docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$CONTAINER_IMAGE-prod:latest
149
+
150
+ - name : Verify EKS Deployment (DEV)
151
+ if : github.ref == 'refs/heads/develop'
152
+ run : |
153
+ kubectl rollout status deployment/automating-metadata-dev
154
+
155
+ - name : Verify EKS Deployment (PROD)
156
+ if : github.ref == 'refs/heads/main'
157
+ run : |
158
+ kubectl rollout status deployment/automating-metadata-prod
159
+
0 commit comments