Skip to content

Commit

Permalink
feat: add workflow
Browse files Browse the repository at this point in the history
trancong12102 committed Sep 10, 2024
1 parent 51de0ea commit 0e4c719
Showing 2 changed files with 40 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build and Push

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch: {}

env:
REGISTRY: ghcr.io
REGISTRY_USER: ${{ github.actor }}
REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

jobs:
build-push:
runs-on: ubuntu-latest
services:
docker:
image: docker:dind
options: --privileged
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
permissions:
contents: read
packages: write
attestations: write
id-token: write
container:
image: ghcr.io/elastic-ee/ci-image:latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Run script
run: |
echo $REGISTRY_PASSWORD | docker login $REGISTRY -u $REGISTRY_USER --password-stdin
bash ./build.sh
5 changes: 4 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ es_version=$(echo $VERSION | cut -d'v' -f2)
REGISTRY=ghcr.io
REPO=elastic-ee/elasticsearch
IMAGE=$REGISTRY/$REPO:$VERSION
LATEST_IMAGE=$REGISTRY/$REPO:latest

# Check if the version is already built
TOKEN=$(curl -s https://ghcr.io/token\?scope\="repository:$REPO:pull" | jq -r .token)
@@ -21,4 +22,6 @@ if curl -f -s -H "Authorization: Bearer $TOKEN" https://ghcr.io/v2/$REPO/manifes
fi

# Build image
docker build --build-arg VERSION=$es_version -t $IMAGE --push .
docker build --build-arg VERSION=$es_version -t $IMAGE --push --cache-from type=registry,ref=$LATEST_IMAGE .
docker tag $IMAGE $LATEST_IMAGE
docker push $LATEST_IMAGE

0 comments on commit 0e4c719

Please sign in to comment.