Skip to content

Commit f084323

Browse files
authored
Merge pull request #173 from CollActionteam/development
Azure production deployment
2 parents 1a2d007 + f849077 commit f084323

40 files changed

Lines changed: 14439 additions & 877 deletions

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.git
2+
node_modules
3+
dist
4+
Dockerfile
5+
Dockerfile.prod

.github/workflows/deploy.yml

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,31 @@ jobs:
1313
name: Build and Deploy
1414
runs-on: ubuntu-latest
1515
steps:
16-
- name: Check out code
16+
- name: Checkout code
1717
uses: actions/checkout@v3
1818

19-
- uses: azure/login@v1
20-
with:
21-
creds: ${{ secrets.AZ_CREDENTIALS }}
22-
23-
- name: Login to Azure Container Registry
19+
- name: Azure Container Registry login
2420
uses: docker/login-action@v2
2521
with:
2622
registry: ${{ secrets.AZ_REGISTRY_URL }}
2723
username: ${{ secrets.AZ_REGISTRY_USERNAME }}
2824
password: ${{ secrets.AZ_REGISTRY_PASSWORD }}
2925

30-
- name: Build, tag, and push image to Azure Container Instances
26+
- name: Build, tag and push image to Azure Container Registry
3127
env:
3228
SERVICE_ACCOUNT_KEY: ${{ secrets.SERVICE_ACCOUNT_KEY }}
3329
ENV_FILE: ${{ secrets.ENV }}
3430
ECR_REGISTRY: ${{ secrets.AZ_REGISTRY_URL }}
3531
ECR_REPOSITORY: collaction-api-${{ env.CURRENT_ENV }}
36-
DOCKER_FILE: ${{ env.CURRENT_ENV == 'production' && 'Dockerfile.prod' || 'Dockerfile' }}
3732
run: |
3833
echo $SERVICE_ACCOUNT_KEY | base64 --decode > serviceAccountKey.json
3934
echo $ENV_FILE | base64 --decode > .env
40-
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:${{ env.CURRENT_ENV }} -f $DOCKER_FILE .
41-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:${{ env.CURRENT_ENV }}
35+
docker build --target ${{ env.CURRENT_ENV }} -t $ECR_REGISTRY/$ECR_REPOSITORY:${{ github.sha }} .
36+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:${{ github.sha }}
4237
43-
- name: Deploy to Azure Container Instances
44-
uses: azure/aci-deploy@v1
45-
env:
46-
ECR_REPOSITORY: collaction-api-${{ env.CURRENT_ENV }}
38+
- name: Deploy to Azure App Service
39+
uses: azure/webapps-deploy@v2
4740
with:
48-
resource-group: ${{ secrets.AZ_RESOURCE_GROUP }}
49-
dns-name-label: api-${{ env.CURRENT_ENV }}
50-
image: ${{ secrets.AZ_REGISTRY_URL }}/${{ env.ECR_REPOSITORY }}:${{ env.CURRENT_ENV }}
51-
registry-login-server: ${{ secrets.AZ_REGISTRY_URL }}
52-
registry-username: ${{ secrets.AZ_REGISTRY_USERNAME }}
53-
registry-password: ${{ secrets.AZ_REGISTRY_PASSWORD }}
54-
name: ${{ env.ECR_REPOSITORY }}
55-
location: 'west europe'
56-
ports: '80 443 3000'
41+
app-name: 'collaction-api-${{ env.CURRENT_ENV }}'
42+
publish-profile: ${{ secrets.AZ_PUBLISH_PROFILE }}
43+
images: '${{ secrets.AZ_REGISTRY_URL }}/collaction-api-${{ env.CURRENT_ENV }}:${{ github.sha }}'

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,3 @@ dist/
6565
test-coverage/
6666
serviceAccountKey.json
6767
serviceAccountKey-prod.json
68-
package-lock.json

Dockerfile

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
1-
FROM node:16-alpine3.12 as development
1+
# Development
2+
FROM node:16-alpine AS development
23

3-
WORKDIR /home/node/app
4+
WORKDIR /usr/src/app
45

56
COPY package*.json ./
67

78
RUN npm i
89

910
COPY . .
1011

11-
RUN npm run build
12-
1312
EXPOSE 3000
1413

1514
CMD ["npm", "run", "start:dev"]
15+
16+
# Production (multi-stage build)
17+
FROM node:16-alpine AS build
18+
19+
WORKDIR /usr/src/app
20+
21+
COPY --chown=node:node package*.json ./
22+
COPY --chown=node:node --from=development /usr/src/app/node_modules ./node_modules
23+
COPY --chown=node:node . .
24+
25+
RUN npm run build
26+
27+
ENV NODE_ENV production
28+
29+
RUN npm ci --only=production && npm cache clean --force
30+
31+
USER node
32+
33+
FROM node:16-alpine AS production
34+
35+
WORKDIR /usr/src/app
36+
37+
COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules
38+
COPY --chown=node:node --from=build /usr/src/app/dist ./dist
39+
COPY --chown=node:node serviceAccountKey.json .
40+
COPY --chown=node:node .env .
41+
COPY --chown=node:node assets ./assets
42+
COPY --chown=node:node assets ./dist/assets
43+
COPY --chown=node:node assets ./dist/src/assets
44+
45+
CMD [ "node", "dist/src/main.js" ]

Dockerfile.prod

Lines changed: 0 additions & 15 deletions
This file was deleted.

azure/container_registry.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ resource "azurerm_container_registry" "collaction" {
33
resource_group_name = azurerm_resource_group.collaction_api.name
44
location = azurerm_resource_group.collaction_api.location
55
sku = "Standard"
6-
}
6+
admin_enabled = true
7+
}

azure/containers.tf

Lines changed: 0 additions & 85 deletions
This file was deleted.

azure/dns.tf

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
resource "azurerm_dns_zone" "collaction_app" {
2+
name = "collaction.app"
3+
resource_group_name = azurerm_resource_group.collaction_api.name
4+
}
5+
6+
resource "azurerm_dns_a_record" "collaction_app_website" {
7+
name = "@"
8+
zone_name = azurerm_dns_zone.collaction_app.name
9+
resource_group_name = azurerm_resource_group.collaction_api.name
10+
ttl = 300
11+
# Website hosted on Vercel
12+
records = ["76.76.21.21"]
13+
}
14+
15+
resource "azurerm_dns_cname_record" "collaction_app_www" {
16+
name = "www"
17+
zone_name = azurerm_dns_zone.collaction_app.name
18+
resource_group_name = azurerm_resource_group.collaction_api.name
19+
ttl = 300
20+
record = "cname.vercel-dns.com"
21+
}
22+
23+
resource "azurerm_dns_zone" "collaction_org" {
24+
name = "collaction.org"
25+
resource_group_name = azurerm_resource_group.collaction_api.name
26+
}
27+
28+
resource "azurerm_dns_a_record" "collaction_org_website" {
29+
name = "@"
30+
zone_name = azurerm_dns_zone.collaction_org.name
31+
resource_group_name = azurerm_resource_group.collaction_api.name
32+
ttl = 300
33+
# Website hosted on Vercel
34+
records = ["76.76.21.21"]
35+
}
36+
37+
resource "azurerm_dns_mx_record" "collaction_org" {
38+
name = "@"
39+
zone_name = azurerm_dns_zone.collaction_org.name
40+
resource_group_name = azurerm_resource_group.collaction_api.name
41+
ttl = 300
42+
43+
record {
44+
preference = 1
45+
exchange = "ASPMX.L.GOOGLE.COM."
46+
}
47+
48+
record {
49+
preference = 5
50+
exchange = "ALT1.ASPMX.L.GOOGLE.COM."
51+
}
52+
53+
record {
54+
preference = 5
55+
exchange = "ALT2.ASPMX.L.GOOGLE.COM."
56+
}
57+
58+
record {
59+
preference = 10
60+
exchange = "ALT3.ASPMX.L.GOOGLE.COM."
61+
}
62+
63+
record {
64+
preference = 10
65+
exchange = "ALT4.ASPMX.L.GOOGLE.COM."
66+
}
67+
68+
record {
69+
preference = 10
70+
exchange = "x3hzrrc76ur7ql23dtzahto3xlxu2tyrgsgosvkpxf5cry4yhffq.mx-verification.google.com."
71+
}
72+
}
73+
74+
resource "azurerm_dns_txt_record" "google-site-verification" {
75+
name = "@"
76+
zone_name = azurerm_dns_zone.collaction_org.name
77+
resource_group_name = azurerm_resource_group.collaction_api.name
78+
ttl = 300
79+
80+
record {
81+
value = "\"google-site-verification=SW8ISEH0mS7aKfOnxzUEjgMyrNyNDX1CkWrc6OBV5Js\""
82+
}
83+
84+
record {
85+
value = "\"google-site-verification=TyCEpqnZwyWaRL1FhYY46fr7faAfDbCP16AOQwQVElw\""
86+
}
87+
88+
record {
89+
value = "\"google-site-verification=Kh1C6nh-U5B6efQFVrwGbD65rs53Ubr_14jiWqiAP9k\""
90+
}
91+
92+
record {
93+
value = "\"MS=ms78684470\""
94+
}
95+
}
96+
97+
# TODO(gm): Connect these to containers
98+
# resource "azurerm_dns_cname_record" "api-production" {
99+
# name = "api"
100+
# zone_name = azurerm_dns_zone.collaction_org.name
101+
# resource_group_name = azurerm_resource_group.collaction_api.name
102+
# ttl = 300
103+
# record = "collaction-api-prod-1123994322.eu-central-1.elb.amazonaws.com."
104+
# }
105+
#
106+
# resource "azurerm_dns_cname_record" "api-dev" {
107+
# name = "devapi"
108+
# zone_name = azurerm_dns_zone.collaction_org.name
109+
# resource_group_name = azurerm_resource_group.collaction_api.name
110+
# ttl = 300
111+
# record = "collaction-api-dev-183571204.eu-central-1.elb.amazonaws.com."
112+
# }
113+
114+
resource "azurerm_dns_cname_record" "docs" {
115+
name = "docs"
116+
zone_name = azurerm_dns_zone.collaction_org.name
117+
resource_group_name = azurerm_resource_group.collaction_api.name
118+
ttl = 300
119+
record = "19caebbc41-hosting.gitbook.io"
120+
}
121+
122+
# TODO(gm): how to connect this to Azure Blob Storage?
123+
# resource "azurerm_dns_a_record" "static-dev" {
124+
# name = "static-dev"
125+
# zone_name = azurerm_dns_zone.collaction_org.name
126+
# resource_group_name = azurerm_resource_group.collaction_api.name
127+
# ttl = 300
128+
# records = [""]
129+
# }
130+
131+
# resource "azurerm_dns_a_record" "static-production" {
132+
# name = "static"
133+
# zone_name = azurerm_dns_zone.collaction_org.name
134+
# resource_group_name = azurerm_resource_group.collaction_api.name
135+
# ttl = 300
136+
# records = [""]
137+
# }
138+
139+
resource "azurerm_dns_cname_record" "collaction_org_www" {
140+
name = "www"
141+
zone_name = azurerm_dns_zone.collaction_org.name
142+
resource_group_name = azurerm_resource_group.collaction_api.name
143+
ttl = 300
144+
record = "cname.vercel-dns.com"
145+
}

0 commit comments

Comments
 (0)