Skip to content

Instantly share code, notes, and snippets.

@Hansanghyeon
Last active March 3, 2023 07:52
Show Gist options
  • Save Hansanghyeon/27fa3b11f7f20005cc2b29ccbc263699 to your computer and use it in GitHub Desktop.
Save Hansanghyeon/27fa3b11f7f20005cc2b29ccbc263699 to your computer and use it in GitHub Desktop.
PPPP
# current버전을 가져올 수 있도록
PACKAGES_FILE := $(CURDIR)/package.json
VERSION := $(shell grep '"version"' $(PACKAGES_FILE) | sed 's/^.*"version": "\(.*\)",.*$$/\1/')
NAME := $(shell grep '"name"' $(PACKAGES_FILE) | sed 's/^.*"name": "\(.*\)",.*$$/\1/')
# @제거해서 도커이미지 이름으로 변경
IMAGENAME := $(subst @,,$(NAME))
# .env사용하기
GH_TOKEN=$(grep GH_TOKEN .env | cut -d '=' -f2)
include .env
BUILD_ARGS = \
GH_TOKEN=$(GH_TOKEN)
# yarnrc
add-ghtoken-yarnrc: npmrc
npmrc:
# npmAlwaysAuth 다음에 새로운 내용 추가하기
sed -i -e 's/@imwebme:registry=https\:\/\/npm.pkg.github.com\//@imwebme:registry=https:\/\/npm.pkg.github.com\/\n\/\/npm.pkg.github.com\/:_authToken=${GH_TOKEN}/g' .npmrc
remove-ghtoken-yarnrc:
sed -i -e '/_authToken/d' .npmrc
# ----------------------------------------
# install
# ----------------------------------------
install-1: add-ghtoken-yarnrc
yarn install
install: install-1 remove-ghtoken-yarnrc
# ----------------------------------------
# github action docker buildx
# ----------------------------------------
build-1: add-ghtoken-yarnrc
@echo "Building image with tag: ghcr.io/${IMAGENAME}:$(VERSION)"; \
docker buildx build \
--platform linux/arm64,linux/amd64 \
-t ghcr.io/imwebme/${IMAGENAME}:$(VERSION) \
--build-arg GH_TOKEN=${GH_TOKEN} \
--push .
#remove yarnrc
build: build-1 remove-ghtoken-yarnrc
# ----------------------------------------
# local docker buildx
# ----------------------------------------
# docker buildx build --platform linux/arm64,linux/amd64 -t ghcr.io/imwebme/zynk-react-icon:0.0.0-alpha.3 --build-arg GH_TOKEN= .
build-local-1: add-ghtoken-yarnrc
@echo "Building image with tag: ghcr.io/imwebme/${IMAGENAME}:$(VERSION)"; \
docker buildx build \
--platform linux/arm64,linux/amd64 \
-t ghcr.io/${IMAGENAME}:$(VERSION) \
$(foreach build_arg,$(BUILD_ARGS),--build-arg $(build_arg)) \
--push .
#remove yarnrc
build-local: build-local-1 remove-ghtoken-yarnrc
# ----------------------------------------
# test
# ----------------------------------------
docker-image-test:
docker run --rm -it -p 3000:3000 ghcr.io/${IMAGENAME}:$(VERSION)
# current버전을 가져올 수 있도록
PACKAGES_FILE := $(CURDIR)/package.json
VERSION := $(shell grep '"version"' $(PACKAGES_FILE) | sed 's/^.*"version": "\(.*\)",.*$$/\1/')
NAME := $(shell grep '"name"' $(PACKAGES_FILE) | sed 's/^.*"name": "\(.*\)",.*$$/\1/')
# @제거해서 도커이미지 이름으로 변경
IMAGENAME := $(subst @,,$(NAME))
# .env사용하기
GH_TOKEN=$(grep GH_TOKEN .env | cut -d '=' -f2)
include .env
BUILD_ARGS = \
GH_TOKEN=$(GH_TOKEN)
# yarnrc
add-ghtoken-yarnrc: yarnrc
yarnrc:
# npmAlwaysAuth 다음에 새로운 내용 추가하기
sed -i -e 's/npmAlwaysAuth: true/npmAlwaysAuth: true\n npmAuthToken: \"${GH_TOKEN}\"/g' .yarnrc.yml
remove-ghtoken-yarnrc:
sed -i -e '/ npmAuthToken/d' .yarnrc.yml
# ----------------------------------------
# install
# ----------------------------------------
install-1: add-ghtoken-yarnrc
yarn install
install: install-1 remove-ghtoken-yarnrc
# ----------------------------------------
# github action docker buildx
# ----------------------------------------
build-1: add-ghtoken-yarnrc
@echo "Building image with tag: ghcr.io/${IMAGENAME}:$(VERSION)"; \
docker buildx build \
--platform linux/arm64,linux/amd64 \
-t ghcr.io/imwebme/${IMAGENAME}:$(VERSION) \
--build-arg GH_TOKEN=${GH_TOKEN} \
--push .
#remove yarnrc
build: build-1 remove-ghtoken-yarnrc
# ----------------------------------------
# local docker buildx
# ----------------------------------------
# docker buildx build --platform linux/arm64,linux/amd64 -t ghcr.io/imwebme/zynk-react-icon:0.0.0-alpha.3 --build-arg GH_TOKEN= .
build-local-1: add-ghtoken-yarnrc
@echo "Building image with tag: ghcr.io/imwebme/${IMAGENAME}:$(VERSION)"; \
docker buildx build \
--platform linux/arm64,linux/amd64 \
-t ghcr.io/${IMAGENAME}:$(VERSION) \
$(foreach build_arg,$(BUILD_ARGS),--build-arg $(build_arg)) \
--push .
#remove yarnrc
build-local: build-local-1 remove-ghtoken-yarnrc
# ----------------------------------------
# test
# ----------------------------------------
docker-image-test:
docker run --rm -it -p 3000:3000 ghcr.io/${IMAGENAME}:$(VERSION)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment