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

Setup docker buildx #5

Merged
merged 2 commits into from
Aug 31, 2023
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
25 changes: 8 additions & 17 deletions .github/workflows/build_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ jobs:
build-deploy-images:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
Expand All @@ -23,9 +29,7 @@ jobs:
uses: aws-actions/amazon-ecr-login@v1

- name: Checkout repo
uses: actions/checkout@v2
with:
ref: master
uses: actions/checkout@v3

- name: Build
env:
Expand All @@ -37,17 +41,4 @@ jobs:
NS_REMOTE: "${{ secrets.ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ACCOUNT_NAME }}"
DOCKER_LOGIN_CMD: "aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
run: |
make build

- name: Deploy
if: ${{ success() }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}
ACCOUNT_NAME: ${{ secrets.ACCOUNT_NAME }}
AWS_REGION: ${{ secrets.AWS_REGION }}
NS_REMOTE: "${{ secrets.ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{ secrets.ACCOUNT_NAME }}"
DOCKER_LOGIN_CMD: "aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
run: |
make tp
make build-push
30 changes: 25 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ define ROOT_IMAGE_TASKS
# Comment this out when debugging
.INTERMEDIATE: $(3)/Dockerfile

.PHONY: build-$(3) clean-local-$(3) kill-$(3) rm-$(3) \
.PHONY: build-$(3) build-push-$(3) clean-local-$(3) kill-$(3) rm-$(3) \
rmf-$(3) squash-$(3) tag-$(3) push-$(3) sp-$(3) \
bsp-$(3) tp-$(3) btp-$(3) bt-$(3) bs-$(3) \
clean-remote-$(3) run-$(3)
Expand All @@ -84,8 +84,11 @@ $(3)/Dockerfile:
echo "$$$${FROM_LINE_EVALED}" > $$@; \
sed '1d' [email protected] >> $$@

# Use this option when local docker supports multi plaform
build-$(3): $(3)/Dockerfile
docker build --rm \
docker buildx build --rm \
--platform linux/amd64,linux/arm64 \
--output type=docker \
-t $(CONTAINER_LOCAL_NAME) \
-f $(3)/Dockerfile \
--label ribose-base-container-root=$(2) \
Expand All @@ -97,6 +100,21 @@ build-$(3): $(3)/Dockerfile
--label ribose-base-container-commit-branch=$(CONTAINER_BRANCH) \
.

build-push-$(3): $(3)/Dockerfile
docker buildx build --rm \
--platform linux/amd64,linux/arm64 \
--output type=image,name=$(CONTAINER_REMOTE_NAME),push=true \
-t $(CONTAINER_REMOTE_NAME) \
-f $(3)/Dockerfile \
--label ribose-base-container-root=$(2) \
--label ribose-base-container-source=$(REPO_GIT_NAME)/$(3) \
--label ribose-base-container=$(CONTAINER_REMOTE_NAME) \
--label ribose-base-container-remote=$(CONTAINER_REMOTE_NAME) \
--label ribose-base-container-version=$(1) \
--label ribose-base-container-commit=$(CONTAINER_COMMIT) \
--label ribose-base-container-commit-branch=$(CONTAINER_BRANCH) \
.

clean-local-$(3):
docker rmi -f $(CONTAINER_LOCAL_NAME)

Expand Down Expand Up @@ -129,12 +147,13 @@ dosquash-$(3):
squash-$(3): | docker-squash-exists $(3)/Dockerfile dosquash-$(3) clean-local-$(3)

dotag-$(3):
CONTAINER_ID=`docker images -q $(CONTAINER_LOCAL_NAME)`; \
if [ "$$$${CONTAINER_ID}" == "" ]; then \
IMAGE_ID=`docker images -q $(CONTAINER_LOCAL_NAME)`; \
if [ "$$$${IMAGE_ID}" == "" ]; then \
echo "Container non-existant, check 'docker images'."; \
exit 1; \
fi; \
docker tag $$$${CONTAINER_ID} $(CONTAINER_REMOTE_NAME)
IMAGE_ID=`echo $$$${IMAGE_ID} | cut -d " " -f1`; \
docker tag $$$${IMAGE_ID} $(CONTAINER_REMOTE_NAME)

tag-$(3): | dotag-$(3) clean-local-$(3)

Expand All @@ -158,4 +177,5 @@ endef
$(foreach i,$(ITEMS),$(eval $(call ROOT_IMAGE_TASKS,$(call GET_VERSION,$i),$(call GET_ROOT_IMAGE,$i),$(call GET_IMAGE_TYPE,$i),$(CONTAINER_TYPE))))

build: $(addprefix build-, $(notdir $(IMAGE_TYPES)))
build-push: $(addprefix build-push-, $(notdir $(IMAGE_TYPES)))
tp: $(addprefix tp-, $(notdir $(IMAGE_TYPES)))
Loading