Skip to content

Commit 6d6b4ef

Browse files
committed
deploy prod with azure
1 parent ce4db66 commit 6d6b4ef

File tree

5 files changed

+51
-77
lines changed

5 files changed

+51
-77
lines changed

.github/workflows/dev-cd.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ jobs:
2020
url: https://dev-codepaster.azurewebsites.net
2121
steps:
2222
- name: Checkout repository
23-
uses: actions/checkout@v3
23+
uses: actions/checkout@v4
2424

2525
- name: Log in to GitHub container registry
26-
uses: docker/login-action@v2
26+
uses: docker/login-action@v3
2727
with:
2828
registry: ghcr.io
2929
username: ${{ github.actor }}
@@ -34,11 +34,11 @@ jobs:
3434
docker build \
3535
--build-arg BASE_API_URL=https://dev-codepaster.azurewebsites.net \
3636
--build-arg BASE_SOCKET_URL=https://dev-codepaster.azurewebsites.net \
37-
-t ${{env.IMAGE_NAME}} -f azure.Dockerfile .
37+
-t ${{env.IMAGE_NAME}} .
3838
docker push ${{env.IMAGE_NAME}}
3939
4040
- name: Deploy to Azure
41-
uses: azure/webapps-deploy@v2
41+
uses: azure/webapps-deploy@v3
4242
with:
4343
app-name: ${{ secrets.DEV_AZURE_APP_NAME }}
4444
publish-profile: ${{ secrets.DEV_AZURE_PUBLISH_PROFILE }}

.github/workflows/prod-cd.yml

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,37 @@ on:
55
push:
66
branches:
77
- master
8-
8+
env:
9+
IMAGE_NAME: ghcr.io/lemoncode/code-paster:prod-${{github.sha}}-${{github.run_attempt}}
10+
911
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://codepaster.net \
15-
BASE_SOCKET_URL=https://codepaster.net"
16-
secrets:
17-
AWS_EB_APP_NAME: ${{secrets.AWS_EB_APP_NAME}}
18-
AWS_EB_ENV_NAME: ${{secrets.AWS_EB_ENV_NAME}}
19-
AWS_DEPLOY_ACCESS_KEY_ID: ${{secrets.AWS_DEPLOY_ACCESS_KEY_ID}}
20-
AWS_DEPLOY_SECRET_ACCESS_KEY: ${{secrets.AWS_DEPLOY_SECRET_ACCESS_KEY}}
21-
AWS_REGION: ${{secrets.AWS_REGION}}
22-
AWS_DEPLOY_S3_BUCKET: ${{secrets.AWS_DEPLOY_S3_BUCKET}}
12+
deploy:
13+
runs-on: ubuntu-latest
14+
environment:
15+
name: "Production"
16+
url: https://codepaster.net/
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Log in to GitHub container registry
22+
uses: docker/login-action@v3
23+
with:
24+
registry: ghcr.io
25+
username: ${{ github.actor }}
26+
password: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Build and push docker image
29+
run: |
30+
docker build \
31+
--build-arg BASE_API_URL=https://codepaster.net \
32+
--build-arg BASE_SOCKET_URL=https://codepaster.net \
33+
-t ${{env.IMAGE_NAME}} .
34+
docker push ${{env.IMAGE_NAME}}
35+
36+
- name: Deploy to Azure
37+
uses: azure/webapps-deploy@v3
38+
with:
39+
app-name: ${{ secrets.PROD_AZURE_APP_NAME }}
40+
publish-profile: ${{ secrets.PROD_AZURE_PUBLISH_PROFILE }}
41+
images: ${{env.IMAGE_NAME}}

Dockerfile

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:12-alpine AS base
1+
FROM node:20-alpine AS base
22
RUN mkdir -p /usr/app
33
WORKDIR /usr/app
44

@@ -20,20 +20,28 @@ RUN npm run build
2020

2121
# Release
2222
FROM base AS release
23+
ENV NODE_ENV=production
24+
ENV STATIC_FILES_PATH=./public
2325
COPY --from=build-backend /usr/app/dist ./
24-
COPY --from=build-frontend /usr/app/dist ./public
26+
COPY --from=build-frontend /usr/app/dist $STATIC_FILES_PATH
2527
COPY ./back/package.json ./
2628
COPY ./back/package-lock.json ./
2729
RUN npm ci --only=production
2830

29-
EXPOSE 3000
30-
ENV INTERNAL_PORT=3000
31+
FROM nasdan/azure-pm2-nginx:nodejs-20-nginx-1.24
3132
ENV NODE_ENV=production
3233
ENV STATIC_FILES_PATH=./public
3334
ENV MOCK_REPOSITORY=false
3435
ENV CORS_ORIGIN=false
3536
ENV API_URL=/api
37+
COPY --from=release /usr/app ./
3638

37-
RUN npm i pm2 -g
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
3843

39-
CMD pm2 start ./index.js --name "app" --env production --no-daemon
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;'

azure.Dockerfile

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

package-lock.json

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

0 commit comments

Comments
 (0)