Skip to content

Commit c0b1986

Browse files
authored
Merge pull request #165 from Lemoncode/develop
Deploy to prod
2 parents 0fe63ea + 6d6b4ef commit c0b1986

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+27036
-38623
lines changed

.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@v4
24+
25+
- name: Log in to GitHub container registry
26+
uses: docker/login-action@v3
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}} .
38+
docker push ${{env.IMAGE_NAME}}
39+
40+
- name: Deploy to Azure
41+
uses: azure/webapps-deploy@v3
42+
with:
43+
app-name: ${{ secrets.DEV_AZURE_APP_NAME }}
44+
publish-profile: ${{ secrets.DEV_AZURE_PUBLISH_PROFILE }}
45+
images: ${{env.IMAGE_NAME}}

.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 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 ./
38+
39+
COPY nginx.conf /etc/nginx/conf.d/default.conf
3640

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

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/docker-compose.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
version: '3'
1+
version: '3.8'
22
services:
33
mongodb-codepaster:
44
container_name: mongodb-codepaster
5-
image: mongo:4.2.10
5+
image: mongo:6
66
ports:
7-
- '27017:27017'
7+
- '27017:27017'
8+
networks:
9+
- codepaster
10+
11+
networks:
12+
codepaster:

0 commit comments

Comments
 (0)