Skip to content

Commit

Permalink
Refactor deployment workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
monzim committed Mar 28, 2024
1 parent 9b928e8 commit 8882653
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ env:
IMAGE_TAG: ${{ github.ref_type == 'tag' && github.ref || contains(github.event.head_commit.message, 'latest') && 'latest' || 'dev' }}

jobs:
push-to-ecr:
push-ghcr:
if: contains(github.event.head_commit.message, 'BUILD') || github.event_name == 'release'
runs-on: ubuntu-latest
env:
IMAGE_TAG: ${{ github.ref_type == 'tag' && github.ref || contains(github.event.head_commit.message, 'latest') && 'latest' || 'dev' }}

steps:
- name: Checkout code
Expand All @@ -31,37 +29,31 @@ jobs:
- name: Install Go dependencies
run: go mod download

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
- name: 🔑 Login to GHCR
uses: docker/login-action@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

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

- name: Build, Tag, and Push the Image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ env.IMAGE_TAG }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GCR_TOKEN }}

- name: 🏗️ Build and push
run: |
if [[ $IMAGE_TAG == *"refs/tags/"* ]]; then
IMAGE_TAG=$(echo $IMAGE_TAG | sed 's/refs\/tags\///')
export IMAGE_TAG
fi
echo "==>> IMAGE_TAG: $IMAGE_TAG"
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker build -t ghcr.io/${{ env.IMAGE_NAME }}:$IMAGE_TAG -t ghcr.io/${{ env.IMAGE_NAME }}:${{ env.SHORT_SHA }} .
docker push ghcr.io/${{ env.IMAGE_NAME }}:${{ env.SHORT_SHA }}
docker push ghcr.io/${{ env.IMAGE_NAME }}:$IMAGE_TAG
build-push-ghcr:
push-ecr:
if: contains(github.event.head_commit.message, 'BUILD') || github.event_name == 'release'
runs-on: ubuntu-latest
env:
IMAGE_TAG: ${{ github.ref_type == 'tag' && github.ref || contains(github.event.head_commit.message, 'latest') && 'latest' || 'dev' }}

steps:
- name: Checkout code
Expand All @@ -75,22 +67,30 @@ jobs:
- name: Install Go dependencies
run: go mod download

- name: 🔑 Login to GHCR
uses: docker/login-action@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GCR_TOKEN }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

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

- name: Build, Tag, and Push the Image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
IMAGE_TAG: ${{ env.IMAGE_TAG }}

- name: 🏗️ Build and push
run: |
if [[ $IMAGE_TAG == *"refs/tags/"* ]]; then
IMAGE_TAG=$(echo $IMAGE_TAG | sed 's/refs\/tags\///')
export IMAGE_TAG
fi
echo "==>> IMAGE_TAG: $IMAGE_TAG"
docker build -t ghcr.io/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} -t ghcr.io/${{ env.IMAGE_NAME }}:${{ env.SHORT_SHA }} .
docker push ghcr.io/${{ env.IMAGE_NAME }}:${{ env.SHORT_SHA }}
docker push ghcr.io/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

0 comments on commit 8882653

Please sign in to comment.