Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Kubernetes changes #192

Merged
merged 8 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions .github/workflows/docker-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
on:
workflow_run:
workflows:
- "Check Code Quality"
branches:
- main
types:
- completed

name: Build and Push to ECR

jobs:
build-and-push:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
name: Build and Push
environment: ${{ startsWith(github.ref, 'refs/tags/') && 'prod' || 'dev' }}
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
commit: ${{ steps.get-commit-id.outputs.commit }}
environment: ${{ steps.set-environment.outputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION }}

- name: Configure Node
uses: actions/setup-node@v4
with:
node-version: 16.13
registry-url: 'https://npm.pkg.github.com'
scope: '@zeplin'
cache: 'npm'

- id: get-commit-id
name: Get commit id
run: echo "commit=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT

- name: Create revision file
run: echo $(date +%s)-${{ steps.get-commit-id.outputs.commit }} >./revision.txt

- id: get-version
name: Get version
run: echo "version=${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || '' }}" >> $GITHUB_OUTPUT

- name: Set package version
if: ${{ steps.get-version.outputs.version }} # ${GITHUB_REF} does not have a tag if this is not set above
run: npm version ${GITHUB_REF#refs/tags/v} --no-git-tag-version --allow-same-version

- id: set-environment
name: Set environment
run: echo "environment=${{ startsWith(github.ref, 'refs/tags/') && 'prod' || 'dev' }}" >> $GITHUB_OUTPUT

- name: Install all dependencies
run: npm ci --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

- name: Run post install scripts of dependencies
run: npm rebuild && npm run prepare --if-present

- name: Build
run: npm run build

- name: Install dependencies without devDependencies
run: npm ci --omit=dev --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

- name: Run post install scripts of dependencies
run: npm rebuild && npm run prepare --if-present

- name: Build and push Docker image to AWS ECR
run: |
REPO="${{ vars.AWS_ACCOUNT_ID || '915497967985' }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com"
IMAGE="$REPO/microsoft-teams-app:${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || steps.get-commit-id.outputs.commit }}"
IMAGE_WITH_ENV_TAG="$REPO/microsoft-teams-app:${{ steps.set-environment.outputs.environment }}"
docker build -t $IMAGE .
docker tag $IMAGE $IMAGE_WITH_ENV_TAG
aws ecr get-login-password --region ${{ vars.AWS_REGION }} | docker login --username AWS --password-stdin $REPO
docker push $IMAGE
docker push $IMAGE_WITH_ENV_TAG

- name: Trigger infra workflow to deploy new image version
run: |
JSON_DATA=$(
jq -n -c \
--arg b "${{ github.ref_name }}" \
--arg t "${{ github.ref_name }}" \
--arg v "${{ steps.get-version.outputs.version }}" \
--arg c "${{ steps.get-commit-id.outputs.commit }}" \
--arg e "${{ steps.set-environment.outputs.environment }}" \
'{"app-name": "microsoft-teams-app", "branch": $b, "version": $v, "tag": $t, "commit-id": $c, "environment": $e }'
)
echo $JSON_DATA | gh workflow run deploy-app.yaml --repo zeplin/infra --json
echo "Workflow is triggered: https://github.com/zeplin/infra/actions/workflows/deploy-app.yaml"
env:
GH_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

post-deploy:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I see, this is similar to scim. Can you remind me why we need these in this file? I mean this could be a dev publish. (@yuqu)

Copy link
Contributor

@yuqu yuqu Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a dev publish it will just create release markers on Newrelic and Sentry for dev environment, we won't see it for prod environment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newrelic shows "related changes" as markers, I'd definitely not want to see it as a related change in its prod version, for example.

Also, the reason I was confused was because I forgot we'll get rid off development.yaml and production.yaml files. We should check if the new docker publish does everything in those files in other services, too (for example public-api does not put markets in the docker publish file).

needs: build-and-push
name: Post Deploy Actions
environment: ${{ needs.build-and-push.outputs.environment }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Create New Relic deployment marker
uses: newrelic/[email protected]
with:
apiKey: ${{ secrets.NEWRELIC_API_KEY }}
guid: ${{ vars.NEWRELIC_APPLICATION_GUID }}
version: ${{ needs.build-and-push.outputs.version || needs.build-and-push.outputs.commit }}
commit: ${{ needs.build-and-push.outputs.commit }}
groupId: ${{ startsWith(github.ref, 'refs/tags/') && 'prod' || github.ref_name }}

- name: Create Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: zeplin
SENTRY_PROJECT: microsoft-teams-app
with:
environment: ${{ needs.build-and-push.outputs.environment }}
version: ${{ needs.build-and-push.outputs.version }}
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:v16.13.0
RUN apt-get update && apt-get install tini
RUN npm install pm2 -g

ENV APP_HOME="/usr/src/app"

WORKDIR ${APP_HOME}

COPY . ${APP_HOME}/

ENTRYPOINT ["tini", "--"]

CMD ["pm2-runtime", "pm2.json"]
Loading
Loading