Skip to content

Commit

Permalink
Merge pull request #165 from Lemoncode/develop
Browse files Browse the repository at this point in the history
Deploy to prod
  • Loading branch information
nasdan authored Sep 23, 2024
2 parents 0fe63ea + 6d6b4ef commit c0b1986
Show file tree
Hide file tree
Showing 50 changed files with 27,036 additions and 38,623 deletions.
49 changes: 36 additions & 13 deletions .github/workflows/dev-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,41 @@ on:
push:
branches:
- develop
env:
IMAGE_NAME: ghcr.io/lemoncode/code-paster:dev-${{github.sha}}-${{github.run_attempt}}

permissions:
contents: 'read'
packages: 'write'

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://dev.codepaster.net \
BASE_SOCKET_URL=https://dev.codepaster.net"
secrets:
AWS_EB_APP_NAME: ${{secrets.DEV_AWS_EB_APP_NAME}}
AWS_EB_ENV_NAME: ${{secrets.DEV_AWS_EB_ENV_NAME}}
AWS_DEPLOY_ACCESS_KEY_ID: ${{secrets.DEV_AWS_DEPLOY_ACCESS_KEY_ID}}
AWS_DEPLOY_SECRET_ACCESS_KEY: ${{secrets.DEV_AWS_DEPLOY_SECRET_ACCESS_KEY}}
AWS_REGION: ${{secrets.DEV_AWS_REGION}}
AWS_DEPLOY_S3_BUCKET: ${{secrets.DEV_AWS_DEPLOY_S3_BUCKET}}
deploy:
runs-on: ubuntu-latest
environment:
name: 'Development'
url: https://dev-codepaster.azurewebsites.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://dev-codepaster.azurewebsites.net \
--build-arg BASE_SOCKET_URL=https://dev-codepaster.azurewebsites.net \
-t ${{env.IMAGE_NAME}} .
docker push ${{env.IMAGE_NAME}}
- name: Deploy to Azure
uses: azure/webapps-deploy@v3
with:
app-name: ${{ secrets.DEV_AZURE_APP_NAME }}
publish-profile: ${{ secrets.DEV_AZURE_PUBLISH_PROFILE }}
images: ${{env.IMAGE_NAME}}
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 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 ./

COPY nginx.conf /etc/nginx/conf.d/default.conf

RUN npm i pm2 -g
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;'
2 changes: 1 addition & 1 deletion back/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NODE_ENV=development
PORT=8081
INTERNAL_PORT=8081
MOCK_REPOSITORY=false
API_URL=/api
CORS_ORIGIN=http://localhost:8080
Expand Down
11 changes: 8 additions & 3 deletions back/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
version: '3'
version: '3.8'
services:
mongodb-codepaster:
container_name: mongodb-codepaster
image: mongo:4.2.10
image: mongo:6
ports:
- '27017:27017'
- '27017:27017'
networks:
- codepaster

networks:
codepaster:
Loading

0 comments on commit c0b1986

Please sign in to comment.