Skip to content

Commit

Permalink
Rebuild docker in CI rather than locally
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszKubuszok committed May 19, 2023
1 parent 1e14b05 commit 924c5f1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
21 changes: 20 additions & 1 deletion .github/workflows/publish-aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ on:
branches:
- master
jobs:
Rebuild-Docker-Image:
if: github.event.head_commit.message == 'Update Docker image'
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Rebuild Docker image
run: |
make rebuild_docker
Build-and-Publish:
runs-on: ubuntu-latest
steps:
Expand All @@ -29,7 +49,6 @@ jobs:
- name: Build
env:
IMG_TPE: ci
EXTRA_ARGS: --privileged
run: |
sudo chown -R 1000 ${{ github.workspace }}
Expand Down
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

.EXPORT_ALL_VARIABLES:

IMG_TPE?=local
DEFAULT_IMG=kubuszok/jekyll:4.2.2-v2

JEKYLL_IMG=kubuszok/jekyll:4.2.2
JEKYLL_IMG?=$(DEFAULT_IMG)
AWS_IMG=mesosphere/aws-cli:1.14.5
EXTRA_ARGS?=-it --privileged --userns=host

WITH_JEKYLL=docker run --rm --volume="${PWD}/src:/srv/jekyll:Z" --volume="${PWD}/bundle:/usr/gem:Z" -e JEKYLL_ENV="${JEKYLL_ENV}" -p 4000:4000 $(EXTRA_ARGS) "${JEKYLL_IMG}-${IMG_TPE}"
WITH_JEKYLL=docker run --rm --volume="${PWD}/src:/srv/jekyll:Z" --volume="${PWD}/bundle:/usr/gem:Z" -e JEKYLL_ENV="${JEKYLL_ENV}" -p 4000:4000 $(EXTRA_ARGS) "${JEKYLL_IMG}"
WITH_AWSCLI=docker run --rm --volume="${PWD}/src/_site:/project" -e AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" -e AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" -e AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" "${AWS_IMG}"

serve:
Expand Down Expand Up @@ -41,17 +41,18 @@ publish:
| xargs --no-run-if-empty $(WITH_AWSCLI) cloudfront create-invalidation --distribution-id "${CF_DISTRIBUTION_ID}" --paths \
|| $(WITH_AWSCLI) cloudfront create-invalidation --distribution-id "${CF_DISTRIBUTION_ID}" --paths '/*'

pull_docker:
@docker pull "${JEKYLL_IMG}-${IMG_TPE}"
@docker pull "${AWS_IMG}"

push_docker:
rebuild_docker:
@docker buildx create --use
@docker buildx build --platform linux/amd64,linux/arm64/v8 --tag "${JEKYLL_IMG}-local" --push .
@docker buildx build --platform linux/amd64,linux/arm64/v8 --tag "${JEKYLL_IMG}" --push .
@docker buildx stop

push_docker_ci:
@docker build --platform linux/amd64 --tag "${JEKYLL_IMG}-ci" --push .
rebuild_docker_local:
@if [ "$(JEKYLL_IMG)" = "$(DEFAULT_IMG)" ]; then \
echo Local docker image should not be names the same as CI one:; \
echo - set up JEKYLL_IMG to something other than $(DEFAULT_IMG)!; \
exit 1; \
fi
@docker build --tag "${JEKYLL_IMG}" --push .

clean:
@rm -rf bundle src/{.jekyll-cache,.jekyll-metadata,_site}
2 changes: 1 addition & 1 deletion src/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ GEM
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.4.0)
mini_portile2 (2.8.2)
nokogiri (1.15.0)
nokogiri (1.15.1)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
pathutil (0.16.2)
Expand Down

0 comments on commit 924c5f1

Please sign in to comment.