From 54e7c05391e0218cde52cf5ac5ce026a4ed640d0 Mon Sep 17 00:00:00 2001 From: Falldog Date: Thu, 18 Apr 2024 13:54:06 +0800 Subject: [PATCH 1/2] upgrade action to v2 to support any kind of image tag * update README to support latest v2 for github action * add Makefile to push new docker image to AwsECR & DockerHub --- Dockerfile | 2 +- Makefile | 26 ++++++++++++++++++++++++++ README.md | 16 +++++++++++++++- action.yml | 14 +++++++++++--- 4 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 Makefile diff --git a/Dockerfile b/Dockerfile index 2469757..d1aa3e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM python:3.11.9-alpine -ARG VERSION="0.8.0" +ARG VERSION="" RUN apk add --no-cache git RUN python -m pip install --no-cache-dir --upgrade pip diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fc8fd8f --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +DMC_VERSION = "0.8.0" + +IMAGE_NAME = hardcoretech/django-migration-checker +IMAGE_TAG ?= latest +IMAGE = $(IMAGE_NAME):$(IMAGE_TAG) + +AWS_REGION ?= us-west-2 +AWS_ACCOUNT_ID ?= xxxx +AWS_ECR_REPO = "$(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com" + + +.PHONY: build push-to-aws-ecr push-to-docker-hub + +build: + docker build -t $(IMAGE_NAME):$(IMAGE_TAG) --build-arg="VERSION=$(DMC_VERSION)" --platform linux/amd64 . + +push-to-aws-ecr: build + aws ecr describe-repositories --repository-names $(IMAGE_NAME) > /dev/null 2>&1 || aws ecr create-repository --repository-name $(IMAGE_NAME) + aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(AWS_ECR_REPO) + + docker tag $(IMAGE_NAME):$(IMAGE_TAG) ${AWS_ECR_REPO}/$(IMAGE_NAME):$(IMAGE_TAG) + docker push ${AWS_ECR_REPO}/$(IMAGE_NAME):$(IMAGE_TAG) + +push-to-docker-hub: build + docker login + docker push $(IMAGE_NAME):$(IMAGE_TAG) diff --git a/README.md b/README.md index 49de6f6..4b0452c 100644 --- a/README.md +++ b/README.md @@ -28,14 +28,28 @@ jobs: fetch-depth: 1 - name: Django Migration Checker - uses: hardcoretech/django-migration-checker-action@v1 + uses: hardcoretech/django-migration-checker-action@v2 with: app-path: app + docker-image-tag: 0.8.0 ``` #### parameter inputs * `app-path`: django app folder path. after `action/checkout`, the working dir would be repository root. +* `docker-image`: docker image name. you are able to change the image hub to private source. +* `docker-image-tag` docker image tag, it should represent version of `django-migration-checker` (python package) + + +## Develop +Why do we need to maintain docker image rather than build it directly in github action? +* Provide the capability for CI environment to use the image to do the checking as well. + +If django-migration-checker package upgraded, need to update and push docker image. Doesn't need to release new github action version. And the version should match with python package version. +* `make push-to-aws-ecr DMC_VERSION= IMAGE_TAG= AWS_ACCOUNT_ID=` +* `make push-to-docker-hub DMC_VERSION= IMAGE_TAG=` + +Only upgrade the version of github action when you change the content of `action.yml`. ## Resource diff --git a/action.yml b/action.yml index efa6174..23d99f5 100644 --- a/action.yml +++ b/action.yml @@ -10,8 +10,16 @@ inputs: required: true default: 'app' + docker-image: + description: 'docker image name' + default: 'docker://hardcoretech/django-migration-checker' + + docker-image-tag: + description: 'docker image tag of django-migration-checker' + default: 'latest' + runs: - using: 'docker' - image: 'Dockerfile' - args: + using: docker + image: "${{ docker-image }}:${{ docker-image-tag }}" + args: - ${{ inputs.app-path }} From 49ee18c7a014efce18d954115878776897b3e24b Mon Sep 17 00:00:00 2001 From: Falldog Date: Thu, 18 Apr 2024 14:08:03 +0800 Subject: [PATCH 2/2] update README for default value --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 4b0452c..8e1f714 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,11 @@ jobs: #### parameter inputs * `app-path`: django app folder path. after `action/checkout`, the working dir would be repository root. + * default: `app` * `docker-image`: docker image name. you are able to change the image hub to private source. + * default: `docker://hardcoretech/django-migration-checker` * `docker-image-tag` docker image tag, it should represent version of `django-migration-checker` (python package) + * default: `latest` ## Develop