Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build docker image using github actions #276

Merged
merged 7 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build Docker Image

on:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}-{{ github.event_name }}
cancel-in-progress: true

jobs:
build-docker-image:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Add SHORT_SHA env property with commit short sha
run: |
SHORT_SHA=$(git rev-parse --short=9 ${{ github.event.pull_request.head.sha }})
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV
echo "Short SHA: $SHORT_SHA"

- name: Make docker image
working-directory: .
run: make docker-build
env:
ETLHASH: stellar/stellar-etl-dev:${SHORT_SHA}

- name: Login to DockerHub
uses: docker/login-action@bb984efc561711aaa26e433c32c3521176eae55b
with:
username: stellardataeng
password: ${{ secrets.DOCKER_CREDS_DEV }}

- name: Push docker image
working-directory: .
run: docker push stellar/stellar-etl-dev:${SHORT_SHA}
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ SUDO := $(shell docker version >/dev/null 2>&1 || echo "sudo")
# https://github.com/opencontainers/image-spec/blob/master/annotations.md
BUILD_DATE := $(shell date -u +%FT%TZ)

ETLHASH=stellar/stellar-etl:$(shell git rev-parse --short=9 HEAD)
DEFAULT_ETLHASH := stellar/stellar-etl:$(shell git rev-parse --short=9 HEAD)
ETLHASH ?= $(DEFAULT_ETLHASH)
Comment on lines +7 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious: why this was split into two vars?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To support both versions - local build and github action build. If we use make docker-build locally, it will use ETLHASH = DEFAULT_ETLHASH. Otherwise, for github action, ETLHASH is passed as override env variable from branch

ETLHASH: stellar/stellar-etl-dev:${SHORT_SHA}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, makes sense. Thanks 🙏


docker-build:
$(SUDO) docker build --platform linux/amd64 --pull --no-cache --label org.opencontainers.image.created="$(BUILD_DATE)" \
Expand Down
Loading