From e8f5badba1489fc49ade060b3e95ec3bd412e576 Mon Sep 17 00:00:00 2001 From: KW Kwan Date: Thu, 31 Aug 2023 15:37:17 +0800 Subject: [PATCH 1/2] Setup docker buildx --- .github/workflows/build_deploy.yml | 10 +++++++--- Makefile | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build_deploy.yml b/.github/workflows/build_deploy.yml index 04c9d29..09b9506 100644 --- a/.github/workflows/build_deploy.yml +++ b/.github/workflows/build_deploy.yml @@ -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: @@ -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: diff --git a/Makefile b/Makefile index 6b608f4..dc1498b 100644 --- a/Makefile +++ b/Makefile @@ -85,7 +85,9 @@ $(3)/Dockerfile: sed '1d' $$@.in >> $$@ 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) \ @@ -129,12 +131,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) From cc38d4cc7dd67896ad0486a4bc23d697c3fe0cca Mon Sep 17 00:00:00 2001 From: KW Kwan Date: Thu, 31 Aug 2023 15:47:08 +0800 Subject: [PATCH 2/2] Direct push to remote repository --- .github/workflows/build_deploy.yml | 15 +-------------- Makefile | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build_deploy.yml b/.github/workflows/build_deploy.yml index 09b9506..66e1df2 100644 --- a/.github/workflows/build_deploy.yml +++ b/.github/workflows/build_deploy.yml @@ -41,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 \ No newline at end of file + make build-push diff --git a/Makefile b/Makefile index dc1498b..1ce451a 100644 --- a/Makefile +++ b/Makefile @@ -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) @@ -84,6 +84,7 @@ $(3)/Dockerfile: echo "$$$${FROM_LINE_EVALED}" > $$@; \ sed '1d' $$@.in >> $$@ +# Use this option when local docker supports multi plaform build-$(3): $(3)/Dockerfile docker buildx build --rm \ --platform linux/amd64,linux/arm64 \ @@ -99,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) @@ -161,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))) \ No newline at end of file