refactor[GLIT-67]: store built image in aws ecr

This commit is contained in:
DukeCaesar 2024-01-30 15:56:44 +08:00
parent 11a9421441
commit 49cacda411
2 changed files with 31 additions and 7 deletions

View file

@ -2,7 +2,7 @@
set -ex
image="ghcr.io/$GITHUB_REPOSITORY"
image="$ECR_REGISTRY/$ECR_REPOSITORY"
tag=$(git tag --points-at HEAD)
if [ -z "$tag" ]; then
@ -10,7 +10,19 @@ if [ -z "$tag" ]; then
fi
echo $image:$tag
docker buildx create --name mybuilder --use || echo 'skip'
docker buildx create --name mybuilder --use --bootstrap || echo 'skip'
docker buildx inspect --bootstrap
docker buildx build --platform linux/amd64,linux/arm64 -t $image:$tag --push .
dockerfile="./Dockerfile"
docker buildx build \
--progress plain \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--cache-from type=registry,ref=${image}:cache \
--cache-to type=registry,image-manifest=true,oci-mediatypes=true,ref=${image}:cache,mode=max \
--compress \
--push \
--platform linux/amd64,linux/arm64 \
-t "$image:$tag" \
-f "${dockerfile}" .
docker buildx imagetools inspect $image:$tag
echo "image=$image:$tag" >> $GITHUB_OUTPUT

View file

@ -14,10 +14,22 @@ jobs:
with:
fetch-depth: 0
- name: Login to ghcr.io
env:
PAT: ${{ secrets.GH_TOKEN }}
run: printf "$PAT" | docker login --username _ --password-stdin ghcr.io
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Add exec permission to docker.sh
run: chmod +x ./.github/workflows/docker.sh
- name: Build and push Docker images
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: glitchd-ecr-repository-${{ secrets.STAGE }}-geth
run: ./.github/workflows/docker.sh