Skip to content

Commit 00cd323

Browse files
committed
new ci job to push to public ecr
Signed-off-by: Anjul Sahu <anjuls@users.noreply.github.com>
1 parent d9298f7 commit 00cd323

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: "VPC Agent build"
2+
run-name: "VPC Agent updated by ${{ github.actor }} and run by ${{ github.triggering_actor }}"
3+
4+
on:
5+
pull_request:
6+
paths:
7+
- .github/workflows/build-and-push.yaml
8+
- **
9+
branches:
10+
- "main"
11+
push:
12+
paths:
13+
- .github/workflows/build-and-push.yaml
14+
- **
15+
branches:
16+
- "main"
17+
18+
permissions: write-all
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.ref }}
22+
cancel-in-progress: true
23+
24+
jobs:
25+
setup:
26+
runs-on: ubuntu-latest
27+
outputs:
28+
SHORT_SHA: ${{ steps.setup.outputs.SHORT_SHA }}
29+
EPOCH_TIMESTAMP: ${{ steps.setup.outputs.EPOCH_TIMESTAMP }}
30+
MONTH: ${{ steps.setup.outputs.MONTH }}
31+
YEAR: ${{ steps.setup.outputs.YEAR }}
32+
CLEAN_BRANCH_NAME: ${{ steps.setup.outputs.CLEAN_BRANCH_NAME }}
33+
AWS_REGION_PROD: ${{ steps.setup.outputs.AWS_REGION_PROD }}
34+
steps:
35+
- name: Set variables
36+
id: setup
37+
run: |
38+
echo "SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
39+
echo "EPOCH_TIMESTAMP=$(date +%s)" >> $GITHUB_OUTPUT
40+
echo "MONTH=$(date +%m)" >> $GITHUB_OUTPUT
41+
echo "YEAR=$(date +%Y)" >> $GITHUB_OUTPUT
42+
echo "AWS_REGION_PROD=us-east-1" >> $GITHUB_OUTPUT
43+
44+
# Handle both PR and push events
45+
if [ "${{ github.event_name }}" = "pull_request" ]; then
46+
BRANCH_NAME="${{ github.base_ref }}"
47+
else
48+
BRANCH_NAME=${GITHUB_REF#refs/heads/}
49+
fi
50+
51+
echo "CLEAN_BRANCH_NAME=$(echo ${BRANCH_NAME} | tr '/' '-')" >> $GITHUB_OUTPUT
52+
53+
54+
55+
build:
56+
needs: [setup]
57+
runs-on: ubuntu-latest
58+
steps:
59+
- uses: actions/checkout@v4
60+
- name: Login to AWS
61+
uses: aws-actions/configure-aws-credentials@v4
62+
with:
63+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
64+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
65+
aws-region: ${{ needs.setup.outputs.AWS_REGION_PROD}}
66+
67+
- name: Login to Amazon ECR
68+
id: login-ecr
69+
uses: aws-actions/amazon-ecr-login@v2
70+
71+
- name: Build and Tag
72+
env:
73+
IMAGE_TAG_SHA: ${{ needs.setup.outputs.SHORT_SHA }}
74+
IMAGE_TAG_BRANCH: ${{ needs.setup.outputs.CLEAN_BRANCH_NAME }}-${{needs.setup.outputs.EPOCH_TIMESTAMP}}
75+
IMAGE_TAG_BRANCH_ORIG: ${{ needs.setup.outputs.CLEAN_BRANCH_NAME }}
76+
IMAGE_TAG_EPOCH_TIMESTAMP: ${{ needs.setup.outputs.EPOCH_TIMESTAMP }}
77+
run: |
78+
echo "Building for repository: public.ecr.aws/y9s1f3r5/drdroid/drd-vpc-agent"
79+
80+
REPO_NAME="public.ecr.aws/y9s1f3r5/drdroid/drd-vpc-agent"
81+
DOCKER_BUILDKIT=1 docker build -f Dockerfile \
82+
--build-arg BUILDKIT_INLINE_CACHE=1 \
83+
--platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v8 \
84+
--cache-from ${REPO_NAME}:$IMAGE_TAG_BRANCH \
85+
--tag ${REPO_NAME}:$IMAGE_TAG_SHA \
86+
--tag ${REPO_NAME}:$IMAGE_TAG_EPOCH_TIMESTAMP \
87+
--tag ${REPO_NAME}:$IMAGE_TAG_BRANCH_ORIG \
88+
--tag ${REPO_NAME}:$IMAGE_TAG_BRANCH .
89+
90+
- name: Push to ECR
91+
if: github.event_name == 'push'
92+
run: |
93+
echo "Pushing to repository: public.ecr.aws/y9s1f3r5/drdroid/drd-vpc-agent"
94+
REPO_NAME="public.ecr.aws/y9s1f3r5/drdroid/drd-vpc-agent"
95+
docker push ${REPO_NAME} --all-tags

0 commit comments

Comments
 (0)