Skip to content

Commit

Permalink
chore: build and push docker image using github actions (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
npazosmendez authored Aug 14, 2024
1 parent ec431ff commit 3913191
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "build-and-push"

on:
push:
branches:
- main
pull_request:

env:
PROD_REGISTRY: "us-docker.pkg.dev/grafanalabs-global/docker-influx2cortex-prod"
DEV_REGISTRY: "us-docker.pkg.dev/grafanalabs-dev/docker-influx2cortex-dev"

permissions:
contents: read
id-token: write

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Generate Tags
run: |
bash scripts/generate-tags.sh > .tag
echo "DOCKER_TAG=$(cat .tag)" >> $GITHUB_ENV
echo "$DOCKER_TAG"
- name: Build And Push
uses: grafana/shared-workflows/actions/push-to-gar-docker@main
with:
push: true
# If we are building main, push to prod and add the 'latest' tag.
registry: "${{ github.ref_name == 'main' && env.PROD_REGISTRY || env.DEV_REGISTRY }}"
tags: |-
${{ env.DOCKER_TAG }}
type=raw,value=latest,enable=${{ github.ref_name == 'main' }}
context: "."
image_name: "influx2cortex"
environment: "${{ github.ref_name == 'main' && 'prod' || 'dev' }}"
16 changes: 11 additions & 5 deletions scripts/generate-tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ export SHELLOPTS # propagate set to children by default
IFS=$'\t\n'
umask 0077

BRANCH=${DRONE_SOURCE_BRANCH:-$(git branch --show-current)}
# In GitHub Actions, GITHUB_HEAD_REF will be set to the PR branch if this is a PR build.
# Otherwise, if it's a push, the branch name will be in GITHUB_REF_NAME.
BRANCH="${DRONE_SOURCE_BRANCH:-${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-$(git branch --show-current)}}}"

if git diff-index --quiet HEAD --
then
if [[ ${DRONE_COMMIT:-unset} == 'unset' ]]
if [[ ${DRONE_COMMIT:-unset} != "unset" ]];
then
GIT_COMMIT="$(git rev-list -1 HEAD)"
>&2 echo "\$DRONE_COMMIT is unset, using last git commit $GIT_COMMIT"
else
GIT_COMMIT="${DRONE_COMMIT}"
>&2 echo "\$DRONE_COMMIT=${DRONE_COMMIT}"
elif [[ ${GITHUB_SHA:-unset} != "unset" ]];
then
GIT_COMMIT="${GITHUB_SHA}"
>&2 echo "\$GITHUB_SHA=${GITHUB_SHA}"
else
GIT_COMMIT="$(git rev-list -1 HEAD)"
>&2 echo "\$DRONE_COMMIT and GITHUB_SHA are unset, using last git commit $GIT_COMMIT"
fi
# no changes
UNIX_TIMESTAMP=$(git show -s --format=%ct "$GIT_COMMIT")
Expand Down

0 comments on commit 3913191

Please sign in to comment.