-
Notifications
You must be signed in to change notification settings - Fork 0
73 lines (60 loc) · 2.19 KB
/
publish-production-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Publish PRODUCTION image
on:
workflow_dispatch:
permissions:
contents: write
jobs:
tag-and-publish-image:
runs-on: ubuntu-latest
env:
ENVIRONMENT: staging
IMAGE_NAME: ${{ vars.PUBLICECR_URI }}
steps:
- name: Fail if branch is not main
if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/main'
run: |
echo "This workflow should not be triggered with workflow_dispatch on a branch other than main"
exit 1
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Get full history to check existing tags
- name: Set up Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Determine new tag
id: tag
run: |
YEAR=$(date +'%Y')
MONTH=$(date +'%m')
DAY=$(date +'%d')
LATEST_TAG=$(git tag --sort=-v:refname | grep -E "^${YEAR}\.${MONTH}\.${DAY}\.[0-9]+$" | head -n 1 || echo "")
if [[ -z "$LATEST_TAG" ]]; then
COUNTER=1
else
COUNTER=$(( ${LATEST_TAG##*.} + 1 ))
fi
NEW_TAG="${YEAR}.${MONTH}.${DAY}.${COUNTER}"
echo "NEW_TAG=${NEW_TAG}" >> $GITHUB_ENV
echo "New tag: $NEW_TAG"
- name: Create Git Tag
run: |
git tag $NEW_TAG
git push origin $NEW_TAG
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.PUBLICECR_UPLOAD_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PUBLICECR_UPLOAD_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.PUBLICECR_REGION }}
- name: Authenticate with AWS Public ECR
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Build a Docker image
run: |
docker build --build-arg DEPLOYMENT_ENV=production -t ${{ vars.PUBLICECR_URI }}:${{ env.NEW_TAG }} .
- name: Publish To AWS ECR
run: |
docker push ${{ vars.PUBLICECR_URI }}:${{ env.NEW_TAG }}