Skip to content

Commit

Permalink
deploy prod with azure
Browse files Browse the repository at this point in the history
  • Loading branch information
nasdan committed Sep 23, 2024
1 parent ce4db66 commit 6d6b4ef
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 77 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/dev-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
url: https://dev-codepaster.azurewebsites.net
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Log in to GitHub container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand All @@ -34,11 +34,11 @@ jobs:
docker build \
--build-arg BASE_API_URL=https://dev-codepaster.azurewebsites.net \
--build-arg BASE_SOCKET_URL=https://dev-codepaster.azurewebsites.net \
-t ${{env.IMAGE_NAME}} -f azure.Dockerfile .
-t ${{env.IMAGE_NAME}} .
docker push ${{env.IMAGE_NAME}}
- name: Deploy to Azure
uses: azure/webapps-deploy@v2
uses: azure/webapps-deploy@v3
with:
app-name: ${{ secrets.DEV_AZURE_APP_NAME }}
publish-profile: ${{ secrets.DEV_AZURE_PUBLISH_PROFILE }}
Expand Down
47 changes: 33 additions & 14 deletions .github/workflows/prod-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,37 @@ on:
push:
branches:
- master

env:
IMAGE_NAME: ghcr.io/lemoncode/code-paster:prod-${{github.sha}}-${{github.run_attempt}}

jobs:
dev-cd:
uses: lemoncode/actions/.github/workflows/aws-ebs.yml@main
with:
files-to-zip: "back/** back/.babelrc front/** front/.babelrc Dockerfile .dockerignore"
dockerArgs: "BASE_API_URL=https://codepaster.net \
BASE_SOCKET_URL=https://codepaster.net"
secrets:
AWS_EB_APP_NAME: ${{secrets.AWS_EB_APP_NAME}}
AWS_EB_ENV_NAME: ${{secrets.AWS_EB_ENV_NAME}}
AWS_DEPLOY_ACCESS_KEY_ID: ${{secrets.AWS_DEPLOY_ACCESS_KEY_ID}}
AWS_DEPLOY_SECRET_ACCESS_KEY: ${{secrets.AWS_DEPLOY_SECRET_ACCESS_KEY}}
AWS_REGION: ${{secrets.AWS_REGION}}
AWS_DEPLOY_S3_BUCKET: ${{secrets.AWS_DEPLOY_S3_BUCKET}}
deploy:
runs-on: ubuntu-latest
environment:
name: "Production"
url: https://codepaster.net/
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to GitHub container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push docker image
run: |
docker build \
--build-arg BASE_API_URL=https://codepaster.net \
--build-arg BASE_SOCKET_URL=https://codepaster.net \
-t ${{env.IMAGE_NAME}} .
docker push ${{env.IMAGE_NAME}}
- name: Deploy to Azure
uses: azure/webapps-deploy@v3
with:
app-name: ${{ secrets.PROD_AZURE_APP_NAME }}
publish-profile: ${{ secrets.PROD_AZURE_PUBLISH_PROFILE }}
images: ${{env.IMAGE_NAME}}
20 changes: 14 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:12-alpine AS base
FROM node:20-alpine AS base
RUN mkdir -p /usr/app
WORKDIR /usr/app

Expand All @@ -20,20 +20,28 @@ RUN npm run build

# Release
FROM base AS release
ENV NODE_ENV=production
ENV STATIC_FILES_PATH=./public
COPY --from=build-backend /usr/app/dist ./
COPY --from=build-frontend /usr/app/dist ./public
COPY --from=build-frontend /usr/app/dist $STATIC_FILES_PATH
COPY ./back/package.json ./
COPY ./back/package-lock.json ./
RUN npm ci --only=production

EXPOSE 3000
ENV INTERNAL_PORT=3000
FROM nasdan/azure-pm2-nginx:nodejs-20-nginx-1.24
ENV NODE_ENV=production
ENV STATIC_FILES_PATH=./public
ENV MOCK_REPOSITORY=false
ENV CORS_ORIGIN=false
ENV API_URL=/api
COPY --from=release /usr/app ./

RUN npm i pm2 -g
COPY nginx.conf /etc/nginx/conf.d/default.conf

ENV INTERNAL_PORT=3000
RUN sed -i -e 's|INTERNAL_PORT|'"$INTERNAL_PORT"'|g' /etc/nginx/conf.d/default.conf

CMD pm2 start ./index.js --name "app" --env production --no-daemon
CMD sh docker-entrypoint.sh && \
sed -i -e 's|PORT|80|g' /etc/nginx/conf.d/default.conf && \
pm2 start ./index.js --name "app" --env production && \
nginx -g 'daemon off;'
47 changes: 0 additions & 47 deletions azure.Dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions package-lock.json

This file was deleted.

0 comments on commit 6d6b4ef

Please sign in to comment.