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: add deployment #30

Closed
wants to merge 1 commit into from
Closed
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
148 changes: 148 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: Build and deploy to Azure
on:
push:
branches:
- '**'

#concurrency:
# group: k8s
# cancel-in-progress: true

jobs:

# check-kubernetes-enabled:
# runs-on: ubuntu-20.04
# outputs:
# kubernetes-enabled: ${{ steps.kubernetes-flag-defined.outputs.DEFINED }}
# steps:
# - id: kubernetes-flag-defined
# if: "${{ env.ENABLE_KUBERNETES != '' }}"
# run: echo "DEFINED=true" >> $GITHUB_OUTPUT
# env:
# ENABLE_KUBERNETES: ${{ secrets.ENABLE_KUBERNETES }}
#
# check-secret:
# runs-on: ubuntu-20.04
# needs: [check-kubernetes-enabled]
# outputs:
# aws-creds-defined: ${{ steps.aws-creds-defined.outputs.DEFINED }}
# kubeconfig-defined: ${{ steps.kubeconfig-defined.outputs.DEFINED }}
# if: needs.check-kubernetes-enabled.outputs.kubernetes-enabled == 'true'
# steps:
# - id: aws-creds-defined
# if: "${{ env.AWS_ACCESS_KEY_ID != '' && env.AWS_SECRET_ACCESS_KEY != '' }}"
# run: echo "DEFINED=true" >> $GITHUB_OUTPUT
# env:
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
#
# - id: kubeconfig-defined
# if: "${{ env.KUBECONFIG != '' }}"
# run: echo "DEFINED=true" >> $GITHUB_OUTPUT
# env:
# KUBECONFIG: ${{ secrets.KUBECONFIG }}


build-frontend:
name: Build frontend images
runs-on: ubuntu-20.04
# needs: [check-secret]
# if: needs.check-secret.outputs.aws-creds-defined == 'true'
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2

# - name: Login to Amazon ECR
# id: login-ecr
# uses: aws-actions/amazon-ecr-login@v1

- name: Log in to GHCR
id: login-ghcr
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Set the image tag
run: echo "IMAGE_NAME=$(echo ghcr.io/${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: Set repository name
run: |
if [ ${{ secrets.CLUSTER_ENV }} == 'staging' ]; then
echo "REPO_NAME=staging-anythink-frontend" >> $GITHUB_ENV
else
echo "REPO_NAME=anythink-frontend" >> $GITHUB_ENV
fi

# - name: Build and push Docker image to GHCR
# uses: docker/build-push-action@v3
# with:
# context: .
# push: true
# tags: ghcr.io${{ steps.login-ecr.outputs.registry }}/${{ env.REPO_NAME }}:${{ env.IMAGE_TAG }}


- name: Build, tag, and push frontend image to GHCR
id: build-image-frontend
run: |
docker build \
-t $IMAGE_NAME \
-f frontend/Dockerfile.aws \
.
docker push $IMAGE_NAME
#
- name: Log in to Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Deploy to Azure Container Instances
run: |
az container create --resource-group Universe2023CopilotRG \
--name ${{ env.REPO_NAME }} \
--image $IMAGE_NAME \
--cpu 1 --memory 1 \
--os-type Linux \
--ports 3000 \
--dns-name-label dartest123 \
--registry-username vanessa-cooper \
--registry-password ${{ secrets.GHCR_TOKEN }} \
--command-line "yarn start"

# deploy:
# name: Deploy latest tag using helm
# runs-on: ubuntu-20.04
# needs:
# - build-frontend
# steps:
# - name: Checkout
# uses: actions/checkout@v3
#
# - name: Create kube config
# run: |
# mkdir -p $HOME/.kube/
# echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
# chmod 600 $HOME/.kube/config
# - name: Install helm
# run: |
# curl -LO https://get.helm.sh/helm-v3.8.0-linux-amd64.tar.gz
# tar -zxvf helm-v3.8.0-linux-amd64.tar.gz
# mv linux-amd64/helm /usr/local/bin/helm
# helm version
# - name: Lint helm charts
# run: helm lint ./charts/
#
# - name: Set the image tag
# run: echo IMAGE_TAG=${GITHUB_REPOSITORY/\//-}-latest >> $GITHUB_ENV
#
# - name: Deploy
# run: |
# helm upgrade --install --timeout 10m anythink-market ./charts/ \
# --set clusterEnv=${{ secrets.CLUSTER_ENV }} \
# --set frontend.image.tag=${{ env.IMAGE_TAG }} \
# --set backend.image.tag=${{ env.IMAGE_TAG }}

Loading