Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nalbam committed Sep 1, 2021
1 parent 16b38ce commit 914ce5b
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 26 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fetch-depth: 1

- name: Docker Build & Push to Docker Hub
uses: opspresso/action-builder@master
uses: opspresso/action-builder@v0.5.0
with:
args: --docker
env:
Expand All @@ -25,12 +25,12 @@ jobs:
TAG_NAME: ${{ github.ref }}
LATEST: "true"

- name: Docker Build & Push to GitHub Package
uses: opspresso/action-builder@master
with:
args: --docker
env:
USERNAME: ${{ secrets.GITHUB_USERNAME }}
PASSWORD: ${{ secrets.GH_PERSONAL_TOKEN }}
REGISTRY: "docker.pkg.github.com"
TAG_NAME: ${{ github.ref }}
# - name: Docker Build & Push to GitHub Package
# uses: opspresso/action-builder@v0.5.0
# with:
# args: --docker
# env:
# USERNAME: ${{ secrets.GITHUB_USERNAME }}
# PASSWORD: ${{ secrets.GH_PERSONAL_TOKEN }}
# REGISTRY: "docker.pkg.github.com"
# TAG_NAME: ${{ github.ref }}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM opspresso/builder
FROM opspresso/builder:v0.10.1

LABEL "com.github.actions.name"="Docker Push"
LABEL "com.github.actions.description"="build, tag and pushes the container"
LABEL "com.github.actions.icon"="anchor"
LABEL "com.github.actions.color"="blue"

LABEL version=v0.2.17
LABEL version=v0.3.0
LABEL repository="https://github.com/opspresso/action-docker"
LABEL maintainer="Jungyoul Yu <me@nalbam.com>"
LABEL homepage="https://opspresso.com/"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
IMAGE_NAME: "USERNAME/IMAGE_NAME"
TAG_NAME: "v0.0.1"
LATEST: "true"
BUILDX: "true"

- name: Docker Build & Push to GitHub Package
uses: opspresso/action-docker@master
Expand All @@ -55,7 +56,9 @@ jobs:
DOCKERFILE: "Dockerfile.aws"
TAG_NAME: "v0.0.1"
LATEST: "true"
BUILDX: "true"
```
## Common env
Name | Description | Default | Required
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.2.17
v0.3.0
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ branding:

runs:
using: docker
image: docker://opspresso/action-docker:v0.2.17
image: docker://opspresso/action-docker:v0.3.0

outputs:
TAG_NAME:
Expand Down
113 changes: 101 additions & 12 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ _docker_tag() {
fi
}

_docker_push() {
_docker_build() {
_command "docker build ${DOCKER_BUILD_ARGS} -t ${IMAGE_URI}:${TAG_NAME} -f ${DOCKERFILE} ${BUILD_PATH}"
docker build ${DOCKER_BUILD_ARGS} -t ${IMAGE_URI}:${TAG_NAME} -f ${DOCKERFILE} ${BUILD_PATH}

Expand All @@ -108,6 +108,68 @@ _docker_push() {
fi
}

_docker_builds() {
TAG_NAMES=""

ARR=(${PLATFORM//,/ })

for V in ${ARR[@]}; do
P="${V//\//-}"

_command "docker build ${DOCKER_BUILD_ARGS} --build-arg ARCH=${V} -t ${IMAGE_URI}:${TAG_NAME}-${P} -f ${DOCKERFILE} ${BUILD_PATH}"
docker build ${DOCKER_BUILD_ARGS} --build-arg ARCH=${V} -t ${IMAGE_URI}:${TAG_NAME}-${P} -f ${DOCKERFILE} ${BUILD_PATH}

_error_check

_command "docker push ${IMAGE_URI}:${TAG_NAME}-${P}"
docker push ${IMAGE_URI}:${TAG_NAME}-${P}

_error_check

TAG_NAMES="${TAG_NAMES},${IMAGE_URI}:${TAG_NAME}-${P}"
done

_docker_manifest ${TAG_NAME} "${TAG_NAMES:1}"

if [ "${LATEST}" == "true" ]; then
_docker_manifest latest "${TAG_NAMES:1}"
fi
}

_docker_manifest() {
_command "docker manifest create ${IMAGE_URI}:${1} ${2}"
docker manifest create ${IMAGE_URI}:${1} ${2}

_error_check

_command "docker manifest inspect ${IMAGE_URI}:${1}"
docker manifest inspect ${IMAGE_URI}:${1}

_command "docker manifest push ${IMAGE_URI}:${1}"
docker manifest push ${IMAGE_URI}:${1}
}

_docker_buildx() {
if [ -z "${PLATFORM}" ]; then
PLATFORM="linux/arm64,linux/amd64"
fi

_command "docker buildx create --use --name opspresso"
docker buildx create --use --name opspresso

_command "docker buildx build ${DOCKER_BUILD_ARGS} -t ${IMAGE_URI}:${TAG_NAME} -f ${DOCKERFILE} ${BUILD_PATH}"
docker buildx build --push ${DOCKER_BUILD_ARGS} -t ${IMAGE_URI}:${TAG_NAME} ${BUILD_PATH} -f ${DOCKERFILE} --platform ${PLATFORM}

_error_check

_command "docker buildx imagetools inspect ${IMAGE_URI}:${TAG_NAME}"
docker buildx imagetools inspect ${IMAGE_URI}:${TAG_NAME}

if [ "${LATEST}" == "true" ]; then
_docker_manifest latest ${IMAGE_URI}:${TAG_NAME}
fi
}

_docker_pre() {
if [ -z "${USERNAME}" ]; then
_error "USERNAME is not set."
Expand All @@ -125,13 +187,17 @@ _docker_pre() {
DOCKERFILE="Dockerfile"
fi

if [ -z "${IMAGE_NAME}" ]; then
IMAGE_NAME="${REPOSITORY}"
fi

if [ -z "${IMAGE_URI}" ]; then
if [ -z "${REGISTRY}" ]; then
IMAGE_URI="${IMAGE_NAME:-${REPOSITORY}}"
IMAGE_URI="${IMAGE_NAME}"
elif [ "${REGISTRY}" == "docker.pkg.github.com" ]; then
IMAGE_URI="${REGISTRY}/${REPOSITORY}/${IMAGE_NAME:-${REPONAME}}"
IMAGE_URI="${REGISTRY}/${REPOSITORY}/${IMAGE_NAME}"
else
IMAGE_URI="${REGISTRY}/${IMAGE_NAME:-${REPOSITORY}}"
IMAGE_URI="${REGISTRY}/${IMAGE_NAME}"
fi
fi

Expand All @@ -146,7 +212,15 @@ _docker() {

_error_check

_docker_push
if [ "${BUILDX}" == "true" ]; then
_docker_buildx
else
if [ "${PLATFORM}" == "" ]; then
_docker_build
else
_docker_builds
fi
fi

_command "docker logout"
docker logout
Expand All @@ -171,8 +245,12 @@ _docker_ecr_pre() {
IMAGE_NAME="${REPOSITORY}"
fi

if [ -z "${REGISTRY}" ]; then
REGISTRY="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
fi

if [ -z "${IMAGE_URI}" ]; then
IMAGE_URI="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${IMAGE_NAME}"
IMAGE_URI="${REGISTRY}/${IMAGE_NAME}"
fi

_docker_tag
Expand All @@ -193,12 +271,15 @@ ${AWS_REGION}
text
EOF

# https://docs.aws.amazon.com/cli/latest/reference/ecr/get-login.html
# _command "aws ecr get-login --no-include-email"
# aws ecr get-login --no-include-email | sh
PUBLIC=$(echo ${REGISTRY} | cut -d'.' -f1)

_command "aws ecr get-login-password ${AWS_ACCOUNT_ID} ${AWS_REGION}"
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/
if [ "${PUBLIC}" == "public" ]; then
_command "aws ecr-public get-login-password --region ${AWS_REGION} ${REGISTRY}"
aws ecr-public get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${REGISTRY}
else
_command "aws ecr get-login-password --region ${AWS_REGION} ${REGISTRY}"
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${REGISTRY}
fi

_error_check

Expand All @@ -208,7 +289,15 @@ EOF
aws ecr create-repository --repository-name ${IMAGE_NAME} --image-tag-mutability ${IMAGE_TAG_MUTABILITY}
fi

_docker_push
if [ "${BUILDX}" == "true" ]; then
_docker_buildx
else
if [ "${PLATFORM}" == "" ]; then
_docker_build
else
_docker_builds
fi
fi
}

if [ -z "${CMD}" ]; then
Expand Down

0 comments on commit 914ce5b

Please sign in to comment.