Skip to content

Commit 7795a1d

Browse files
committed
migrate to azure dev
1 parent 6ce20fe commit 7795a1d

6 files changed

Lines changed: 110 additions & 16 deletions

File tree

.github/workflows/dev-cd.yml

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,41 @@ on:
55
push:
66
branches:
77
- develop
8+
env:
9+
IMAGE_NAME: ghcr.io/lemoncode/code-paster:dev-${{github.sha}}-${{github.run_attempt}}
10+
11+
permissions:
12+
contents: 'read'
13+
packages: 'write'
814

915
jobs:
10-
dev-cd:
11-
uses: lemoncode/actions/.github/workflows/aws-ebs.yml@main
12-
with:
13-
files-to-zip: "back/** back/.babelrc front/** front/.babelrc Dockerfile .dockerignore"
14-
dockerArgs: "BASE_API_URL=https://dev.codepaster.net \
15-
BASE_SOCKET_URL=https://dev.codepaster.net"
16-
secrets:
17-
AWS_EB_APP_NAME: ${{secrets.DEV_AWS_EB_APP_NAME}}
18-
AWS_EB_ENV_NAME: ${{secrets.DEV_AWS_EB_ENV_NAME}}
19-
AWS_DEPLOY_ACCESS_KEY_ID: ${{secrets.DEV_AWS_DEPLOY_ACCESS_KEY_ID}}
20-
AWS_DEPLOY_SECRET_ACCESS_KEY: ${{secrets.DEV_AWS_DEPLOY_SECRET_ACCESS_KEY}}
21-
AWS_REGION: ${{secrets.DEV_AWS_REGION}}
22-
AWS_DEPLOY_S3_BUCKET: ${{secrets.DEV_AWS_DEPLOY_S3_BUCKET}}
16+
deploy:
17+
runs-on: ubuntu-latest
18+
environment:
19+
name: 'Development'
20+
url: https://dev-codepaster.azurewebsites.net
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v3
24+
25+
- name: Log in to GitHub container registry
26+
uses: docker/login-action@v2
27+
with:
28+
registry: ghcr.io
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Build and push docker image
33+
run: |
34+
docker build \
35+
--build-arg BASE_API_URL=https://dev-codepaster.azurewebsites.net \
36+
--build-arg BASE_SOCKET_URL=https://dev-codepaster.azurewebsites.net \
37+
-t ${{env.IMAGE_NAME}} -f azure.Dockerfile .
38+
docker push ${{env.IMAGE_NAME}}
39+
40+
- name: Deploy to Azure
41+
uses: azure/webapps-deploy@v2
42+
with:
43+
app-name: ${{ secrets.DEV_AZURE_APP_NAME }}
44+
publish-profile: ${{ secrets.DEV_AZURE_PUBLISH_PROFILE }}
45+
images: ${{env.IMAGE_NAME}}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ COPY ./back/package-lock.json ./
2727
RUN npm ci --only=production
2828

2929
EXPOSE 3000
30-
ENV PORT=3000
30+
ENV INTERNAL_PORT=3000
3131
ENV NODE_ENV=production
3232
ENV STATIC_FILES_PATH=./public
3333
ENV MOCK_REPOSITORY=false

azure.Dockerfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
FROM node:16-alpine AS base
2+
RUN mkdir -p /usr/app
3+
WORKDIR /usr/app
4+
5+
# Build front
6+
FROM base AS build-frontend
7+
ARG BASE_API_URL
8+
ENV BASE_API_URL=$BASE_API_URL
9+
ARG BASE_SOCKET_URL
10+
ENV BASE_SOCKET_URL=$BASE_SOCKET_URL
11+
COPY ./front ./
12+
RUN npm ci
13+
RUN npm run build
14+
15+
# Build backend
16+
FROM base AS build-backend
17+
COPY ./back ./
18+
RUN npm ci
19+
RUN npm run build
20+
21+
# Release
22+
FROM base AS release
23+
ENV NODE_ENV=production
24+
ENV STATIC_FILES_PATH=./public
25+
COPY --from=build-backend /usr/app/dist ./
26+
COPY --from=build-frontend /usr/app/dist $STATIC_FILES_PATH
27+
COPY ./back/package.json ./
28+
COPY ./back/package-lock.json ./
29+
RUN npm ci --only=production
30+
31+
FROM nasdan/azure-pm2-nginx
32+
ENV NODE_ENV=production
33+
ENV STATIC_FILES_PATH=./public
34+
ENV MOCK_REPOSITORY=false
35+
ENV CORS_ORIGIN=false
36+
ENV API_URL=/api
37+
COPY --from=release /usr/app ./
38+
39+
COPY nginx.conf /etc/nginx/conf.d/default.conf
40+
41+
ENV INTERNAL_PORT=3000
42+
RUN sed -i -e 's|INTERNAL_PORT|'"$INTERNAL_PORT"'|g' /etc/nginx/conf.d/default.conf
43+
44+
CMD sh docker-entrypoint.sh && \
45+
sed -i -e 's|PORT|80|g' /etc/nginx/conf.d/default.conf && \
46+
pm2 start ./index.js --name "app" --env production && \
47+
nginx -g 'daemon off;'

back/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
NODE_ENV=development
2-
PORT=8081
2+
INTERNAL_PORT=8081
33
MOCK_REPOSITORY=false
44
API_URL=/api
55
CORS_ORIGIN=http://localhost:8080

back/src/core/constants/env.constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const envConstants = {
22
NODE_ENV: process.env.NODE_ENV,
3-
PORT: process.env.PORT,
3+
PORT: process.env.INTERNAL_PORT,
44
isMockRepository: process.env.MOCK_REPOSITORY === 'true',
55
MONGODB_URI: process.env.MONGODB_URI,
66
API_URL: process.env.API_URL,

nginx.conf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
upstream app {
2+
server 127.0.0.1:INTERNAL_PORT;
3+
}
4+
5+
server {
6+
listen PORT default_server;
7+
8+
server_name _;
9+
10+
if ($http_x_forwarded_proto != "https") {
11+
return 301 https://$host$request_uri;
12+
}
13+
14+
proxy_http_version 1.1;
15+
proxy_set_header Upgrade $http_upgrade;
16+
proxy_set_header Connection 'upgrade';
17+
proxy_set_header Host $host;
18+
proxy_cache_bypass $http_upgrade;
19+
20+
location / {
21+
client_max_body_size 10m;
22+
proxy_pass http://app;
23+
}
24+
}

0 commit comments

Comments
 (0)