Skip to content

Commit

Permalink
do not upload as artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmwang committed Sep 19, 2024
1 parent 07fa476 commit f1c2e0d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 240 deletions.
188 changes: 16 additions & 172 deletions .github/workflows/cd-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,127 +13,9 @@ on:
type: number
default: 86400

env:
artifact-retention-days: 3

jobs:
# build-push-backend:
# name: Build Backend Image
# runs-on: ubuntu-latest
# outputs:
# sha_short: ${{ steps.vars.outputs.sha_short }}

# steps:
# - name: Checkout Repository
# uses: actions/checkout@v4

# - name: Set vars
# id: vars
# run: |
# echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV
# echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT

# - name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}

# - name: Build and Push Image with Tag
# run: |
# docker build --platform=linux/amd64 --target backend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ env.sha_short }}" .
# docker push "${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ env.sha_short }}"

# build-push-frontend:
# name: Build Frontend Image
# runs-on: ubuntu-latest
# outputs:
# sha_short: ${{ steps.vars.outputs.sha_short }}

# steps:
# - name: Checkout Repository
# uses: actions/checkout@v4

# - name: Set vars
# id: vars
# run: |
# echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV
# echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT

# - name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}

# - name: Build and Push Image with Tag
# run: |
# docker build --platform=linux/amd64 --target frontend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ env.sha_short }}" .
# docker push "${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ env.sha_short }}"

# deploy:
# name: Deploy with SSH
# needs: [build-push-backend, build-push-frontend]
# runs-on: ubuntu-latest
# environment: development

# steps:
# - name: Receive sha_short
# run: echo "sha_short=${{ needs.build-push-backend.outputs.sha_short }}" >> $GITHUB_ENV

# - name: SSH and Helm Install
# uses: appleboy/[email protected]
# with:
# host: ${{ secrets.SSH_HOST }}
# username: root
# key: ${{ secrets.SSH_KEY }}
# script: |
# cd ./infra
# helm uninstall bt-dev-app-${{ env.sha_short }} || true
# helm install bt-dev-app-${{ env.sha_short }} ./app --namespace=bt \
# --set env=dev \
# --set ttl=${{ inputs.ttl }} \
# --set frontend.image.tag=${{ env.sha_short }} \
# --set backend.image.tag=${{ env.sha_short }} \
# --set host=${{ env.sha_short }}.stanfurdtime.com \
# --set mongoUri=mongodb://bt-dev-mongo-mongodb.bt.svc.cluster.local:27017/bt \
# --set redisUri=redis://bt-dev-redis-master.bt.svc.cluster.local:6379 \
# --set nodeEnv=development

build-backend:
name: Build Backend Image
runs-on: ubuntu-latest
outputs:
sha_short: ${{ steps.vars.outputs.sha_short }}

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set vars
id: vars
run: |
echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV
echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT
- name: Build Image with Tag
id: build
run: |
docker build --platform=linux/amd64 --target backend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ env.sha_short }}" .
docker save "${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ env.sha_short }}" --output "bt-backend-${{ env.sha_short }}.tar"
- name: Upload Image as Artifact
if: steps.build.conclusion == 'success'
uses: actions/upload-artifact@v4
with:
name: "bt-backend-${{ env.sha_short }}.tar"
path: "bt-backend-${{ env.sha_short }}.tar"
retention-days: ${{ env.artifact-retention-days }}
compression-level: 0
overwrite: true

build-frontend:
name: Build Frontend Image
build-push-backend:
name: Build and Push Backend Image
runs-on: ubuntu-latest
outputs:
sha_short: ${{ steps.vars.outputs.sha_short }}
Expand All @@ -148,91 +30,53 @@ jobs:
echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV
echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT
- name: Build Image with Tag
id: build
run: |
docker build --platform=linux/amd64 --target frontend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ env.sha_short }}" .
docker save "${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ env.sha_short }}" --output "bt-frontend-${{ env.sha_short }}.tar"
- name: Upload Image as Artifact
if: steps.build.conclusion == 'success'
uses: actions/upload-artifact@v4
with:
name: "bt-frontend-${{ env.sha_short }}.tar"
path: "bt-frontend-${{ env.sha_short }}.tar"
retention-days: ${{ env.artifact-retention-days }}
compression-level: 0
overwrite: true

push-backend:
name: Push Backend Image
needs: build-backend
runs-on: ubuntu-latest
outputs:
sha_short: ${{ steps.vars.outputs.sha_short }}

steps:
- name: Receive and Forward sha_short
id: vars
run: |
echo "sha_short=${{ needs.build-backend.outputs.sha_short }}" >> $GITHUB_ENV
echo "sha_short=${{ needs.build-backend.outputs.sha_short }}" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Download Artifact as Image
uses: actions/download-artifact@v4
with:
name: "bt-backend-${{ env.sha_short }}.tar"

- name: Push Image to Docker Hub
- name: Build and Push Image with Tag
run: |
docker import "bt-backend-${{ env.sha_short }}.tar" "${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ env.sha_short }}"
docker build --platform=linux/amd64 --target backend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ env.sha_short }}" .
docker push "${{ secrets.DOCKER_USERNAME }}/bt-backend:${{ env.sha_short }}"
push-frontend:
name: Push Frontend Image
needs: build-frontend
build-push-frontend:
name: Build and Push Frontend Image
runs-on: ubuntu-latest
outputs:
sha_short: ${{ steps.vars.outputs.sha_short }}

steps:
- name: Receive and Forward sha_short
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set vars
id: vars
run: |
echo "sha_short=${{ needs.build-frontend.outputs.sha_short }}" >> $GITHUB_ENV
echo "sha_short=${{ needs.build-frontend.outputs.sha_short }}" >> $GITHUB_OUTPUT
echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV
echo "sha_short=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Download Artifact as Image
uses: actions/download-artifact@v4
with:
name: "bt-frontend-${{ env.sha_short }}.tar"

- name: Push Image to Docker Hub
- name: Build and Push Image with Tag
run: |
docker import "bt-frontend-${{ env.sha_short }}.tar" "${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ env.sha_short }}"
docker build --platform=linux/amd64 --target frontend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ env.sha_short }}" .
docker push "${{ secrets.DOCKER_USERNAME }}/bt-frontend:${{ env.sha_short }}"
deploy:
name: Deploy with SSH
needs: [push-backend, push-frontend]
needs: [build-push-backend, build-push-frontend]
runs-on: ubuntu-latest
environment: development

steps:
- name: Receive sha_short
run: echo "sha_short=${{ needs.push-backend.outputs.sha_short }}" >> $GITHUB_ENV
run: echo "sha_short=${{ needs.build-push-backend.outputs.sha_short }}" >> $GITHUB_ENV

- name: SSH and Helm Install
uses: appleboy/[email protected]
Expand Down
83 changes: 15 additions & 68 deletions .github/workflows/cd-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,110 +5,57 @@ concurrency: prod
on:
workflow_dispatch:

env:
artifact-retention-days: 7

jobs:
build-backend:
name: Build Backend Image
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Build Image with Tag
run: |
docker build --target backend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod" .
docker save "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod" --output "bt-backend-prod.tar"
- name: Upload Image as Artifact
uses: actions/upload-artifact@v4
with:
name: "bt-backend-prod.tar"
path: "bt-backend-prod.tar"
retention-days: ${{ env.artifact-retention-days }}
overwrite: true

build-frontend:
name: Build Frontend Image
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Build Image with Tag
run: |
docker build --target frontend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod" .
docker save "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod" --output "bt-frontend-prod.tar"
- name: Upload Image as Artifact
uses: actions/upload-artifact@v4
with:
name: "bt-frontend-prod.tar"
path: "bt-frontend-prod.tar"
retention-days: ${{ env.artifact-retention-days }}
overwrite: true

branch-check:
name: Environment Check
needs: [build-backend, build-frontend]
runs-on: ubuntu-latest
environment: production

steps:
- name: Pass
run: echo "Passed check"

push-backend:
name: Push Backend Image
needs: branch-check
build-push-backend:
name: Build and Push Backend Image
runs-on: ubuntu-latest
environment: prod

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Download Artifact as Image
uses: actions/download-artifact@v4
with:
name: "bt-backend-prod.tar"

- name: Push Image to Docker Hub
- name: Build and Push Image with Tag
run: |
docker import "bt-backend-prod.tar" "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod"
docker build --target backend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod" .
docker push "${{ secrets.DOCKER_USERNAME }}/bt-backend:prod"
push-frontend:
name: Push Frontend Image
needs: branch-check
build-push-frontend:
name: Build and Push Frontend Image
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Download Artifact as Image
uses: actions/download-artifact@v4
with:
name: "bt-frontend-prod.tar"

- name: Push Image to Docker Hub
- name: Build and Push Image with Tag
run: |
docker import "bt-frontend-prod.tar" "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod"
docker build --target frontend-prod --tag "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod" .
docker push "${{ secrets.DOCKER_USERNAME }}/bt-frontend:prod"
deploy:
name: Deploy with SSH
needs: [push-backend, push-frontend]
needs: [build-push-backend, build-push-frontend]
runs-on: ubuntu-latest

steps:
Expand Down

0 comments on commit f1c2e0d

Please sign in to comment.