Skip to content

Commit

Permalink
Merge pull request #125 from Lemoncode/develop
Browse files Browse the repository at this point in the history
Merge to master
  • Loading branch information
nasdan committed Mar 27, 2023
2 parents 128dbd0 + c3e52b8 commit 2f9f53d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 143 deletions.
64 changes: 22 additions & 42 deletions .github/workflows/dev-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,40 @@ on:
branches:
- develop
env:
IMAGE_NAME: ${{secrets.AWS_DOCKER_REGISTRY}}/tshirtplanning:dev-${GITHUB_SHA}-${GITHUB_RUN_ATTEMPT}
IMAGE_NAME: ghcr.io/lemoncode/planning-poker-example:dev-${{github.run_number}}-${{github.run_attempt}}

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

jobs:
build-image:
deploy:
runs-on: ubuntu-latest
environment:
name: 'Development'
url: https://dev.tshirtplanning.com
url: https://dev-tshirtplanning.azurewebsites.net
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: AWS login
uses: aws-actions/configure-aws-credentials@v1-node16

- name: Log in to GitHub container registry
uses: docker/login-action@v2
with:
aws-access-key-id: ${{ secrets.AWS_DEPLOY_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_DEPLOY_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v1
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.tshirtplanning.com \
--build-arg BASE_APP_URL=https://dev.tshirtplanning.com \
--build-arg BASE_API_URL=https://dev-tshirtplanning.azurewebsites.net \
--build-arg BASE_APP_URL=https://dev-tshirtplanning.azurewebsites.net \
-t ${{env.IMAGE_NAME}} .
docker push ${{env.IMAGE_NAME}}
deploy:
needs: [build-image]
uses: lemoncode/actions/.github/workflows/aws-ec2-docker-deploy.yml@main
secrets:
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_EC2_INSTANCE_ID: ${{secrets.DEV_AWS_EC2_INSTANCE_ID}}
AWS_DOCKER_REGISTRY: ${{secrets.AWS_DOCKER_REGISTRY}}
DOCKER_IMAGE_NAME: ${{secrets.AWS_DOCKER_REGISTRY}}/tshirtplanning:dev-${GITHUB_SHA}-${GITHUB_RUN_ATTEMPT}
DOCKER_RUN_PARAMS: -p 3000:3000
S3_ENV_FILE_BUCKET: ${{secrets.ENV_BUCKET_NAME}}
S3_ENV_FILE_KEY: ${{secrets.DEV_ENV_BUCKET_KEY}}
SSH_KEY: ${{secrets.SSH_KEY}}
SSH_USER: ${{secrets.SSH_USER}}

configure-https:
needs: [deploy]
uses: lemoncode/actions/.github/workflows/aws-ec2-configure-https.yml@main
with:
dockerExposedPort: 3000
secrets:
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_EC2_INSTANCE_ID: ${{secrets.DEV_AWS_EC2_INSTANCE_ID}}
SSH_KEY: ${{secrets.SSH_KEY}}
SSH_USER: ${{secrets.SSH_USER}}
DOMAIN_RECORD_NAME: ${{secrets.DEV_AWS_DOMAIN_RECORD_NAME}}
EMAIL: ${{secrets.CERT_EMAIL}}
- name: Deploy to Azure
uses: azure/webapps-deploy@v2
with:
app-name: ${{ secrets.DEV_AZURE_APP_NAME }}
publish-profile: ${{ secrets.DEV_AZURE_PUBLISH_PROFILE }}
images: ${{env.IMAGE_NAME}}
30 changes: 0 additions & 30 deletions .github/workflows/dev-init-server-config.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .github/workflows/dev-update-dns-record.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/prod-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches:
- master
env:
IMAGE_NAME: ghcr.io/lemoncode/planning-poker-example:prod-${GITHUB_SHA}-${GITHUB_RUN_ATTEMPT}
IMAGE_NAME: ghcr.io/lemoncode/planning-poker-example:prod-${{github.run_number}}-${{github.run_attempt}}

permissions:
contents: 'read'
Expand Down Expand Up @@ -34,12 +34,12 @@ jobs:
docker build \
--build-arg BASE_API_URL=https://tshirtplanning.com \
--build-arg BASE_APP_URL=https://tshirtplanning.com \
-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
with:
app-name: ${{ secrets.AZURE_APP_NAME }}
publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }}
images: ${{ env.IMAGE_NAME }}
images: ${{env.IMAGE_NAME}}
18 changes: 13 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,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
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;'
46 changes: 0 additions & 46 deletions azure.Dockerfile

This file was deleted.

5 changes: 4 additions & 1 deletion back/src/core/servers/express.server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import express from 'express';
import bodyParser from 'body-parser';
import { corsOptions } from './cors';
import { envConstants } from 'core/constants';

export const createApp = () => {
const app = express();

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(corsOptions);
if (envConstants.CORS_ORIGIN !== 'false') {
app.use(corsOptions);
}

return app;
};

0 comments on commit 2f9f53d

Please sign in to comment.