Skip to content

Commit

Permalink
Push image
Browse files Browse the repository at this point in the history
  • Loading branch information
chankiyu22 committed Sep 20, 2024
1 parent 593eef9 commit dab1569
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ on:
push:
branches:
- '*'
- '!gh-pages'
tags:
- '*'
pull_request:
branches:
- '*'
- '!gh-pages'

jobs:
test:
Expand All @@ -30,3 +34,27 @@ jobs:
if: ${{ !cancelled() }}
- run: make check-tidy
if: ${{ !cancelled() }}

image:
runs-on: ubuntu-24.04
needs: ["test"]
env:
TARGET: server
IMAGE_NAME: authgear-sms-gateway
steps:
- uses: actions/checkout@v4
- run: make build-image TARGET=$TARGET IMAGE_NAME=$IMAGE_NAME
- run: make tag-image IMAGE_NAME=$IMAGE_NAME
- name: docker login
if: ${{ github.repository == 'authgear/authgear-sms-gateway' && github.event_name == 'push' }}
env:
DOCKER_USERNAME: ${{ secrets.QUAY_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.QUAY_ROBOT_TOKEN }}
run: |
printf "$DOCKER_PASSWORD" | docker login --password-stdin --username "$DOCKER_USERNAME" quay.io
- run: make push-image IMAGE_NAME=$IMAGE_NAME
if: ${{ github.repository == 'authgear/authgear-sms-gateway' && github.event_name == 'push' }}
- name: docker logout
if: ${{ always() }}
run: |
docker logout quay.io
21 changes: 18 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# GIT_NAME could be empty.
GIT_NAME ?= $(shell git describe --exact-match 2>/dev/null)
GIT_HASH ?= git-$(shell git rev-parse --short=12 HEAD)
IMAGE ?= quay.io/theauthgear/authgear-sms-gateway:$(GIT_HASH)

.PHONY: vendor
vendor:
Expand Down Expand Up @@ -45,8 +46,22 @@ check-tidy:

.PHONY: build-image
build-image:
docker build --pull --file ./cmd/server/Dockerfile --tag $(IMAGE) .
docker build --pull --file ./cmd/$(TARGET)/Dockerfile --tag $(IMAGE_NAME) --build-arg GIT_HASH=$(GIT_HASH) .

.PHONY: tag-image
tag-image: DOCKER_IMAGE = quay.io/theauthgear/$(IMAGE_NAME)
tag-image:
docker tag $(IMAGE_NAME) $(DOCKER_IMAGE):latest
docker tag $(IMAGE_NAME) $(DOCKER_IMAGE):$(GIT_HASH)
if [ ! -z $(GIT_NAME) ]; then docker tag $(IMAGE_NAME) $(DOCKER_IMAGE):$(GIT_NAME); fi

.PHONY: push-image
push-image: DOCKER_IMAGE = quay.io/theauthgear/$(IMAGE_NAME)
push-image:
docker push $(IMAGE)
docker manifest inspect $(DOCKER_IMAGE):$(GIT_HASH) > /dev/null; if [ $$? -eq 0 ]; then \
echo "$(DOCKER_IMAGE):$(GIT_HASH) exists. Skip push"; \
else \
docker push $(DOCKER_IMAGE):latest ;\
docker push $(DOCKER_IMAGE):$(GIT_HASH) ;\
if [ ! -z $(GIT_NAME) ]; then docker push $(DOCKER_IMAGE):$(GIT_NAME); fi ;\
fi

0 comments on commit dab1569

Please sign in to comment.