Skip to content

Commit

Permalink
[docker] Add docker image build (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
manugarg authored Jan 13, 2024
1 parent c76954c commit 106c6d7
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,39 @@ jobs:
TWINE_PASSWORD: ${{ secrets.PYPI }}
run: |
twine upload src/pymod/dist/*
build_and_push_docker_multiarch:
name: Build and push multiarch docker image
if: github.repository == 'manugarg/pacparser' && (github.ref == 'refs/heads/master' || startswith(github.ref, 'refs/heads/docker') || startsWith(github.ref, 'refs/tags/v'))
runs-on: ubuntu-latest

steps:
- name: Check out code into the Go module directory
if: ${{ !contains(github.event_name, 'workflow_dispatch') }}
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Check out code into the Go module directory
if: ${{ contains(github.event_name, 'workflow_dispatch') }}
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.inputs.tag }}

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

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

- name: Login to GHCR
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push release Docker Image (main-ghcr)
run: make docker_multiarch DOCKER_IMAGE=ghcr.io/manugarg/pacparser

22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Use Alpine Linux as the base image
FROM alpine:latest as build-stage

# Install build dependencies
RUN apk update && apk add --no-cache \
gcc \
git \
g++ \
bash \
make

WORKDIR /build
COPY src /build
RUN make pactester

# Final stage
FROM alpine:latest

WORKDIR /app
COPY --from=build-stage /build/pactester /app/

CMD /app/pactester
16 changes: 16 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ endif

VERSION ?= $(shell git describe --always --tags --candidate=100)

GIT_TAG := $(shell git describe --exact-match --exclude tip --tags HEAD 2>/dev/null || /bin/true)
DOCKER_IMAGE ?= manugarg/cloudprober
ifeq "$(GIT_TAG)" ""
DOCKER_TAGS := -t $(DOCKER_IMAGE):master -t $(DOCKER_IMAGE):main
else
DOCKER_TAGS := -t $(DOCKER_IMAGE):$(GIT_TAG) -t $(DOCKER_IMAGE):latest
endif

OS_ARCH := $(subst /,_,$(shell uname -s | sed /\ /s//_/))

LIBRARY_NAME = libpacparser
Expand Down Expand Up @@ -155,6 +163,14 @@ pymod-dist: pacparser.o pacparser.h spidermonkey/libjs.a
install-pymod: pymod
cd pymod && ARCHFLAGS="" $(PYTHON) setup.py install --root="$(DESTDIR)/" $(EXTRA_ARGS)

docker_multiarch: pactester Dockerfile
docker buildx build --push \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VERSION=$(VERSION) \
--build-arg VCS_REF=$(GIT_COMMIT) \
--platform linux/amd64,linux/arm64,linux/arm/v7 \
$(DOCKER_TAGS) .

clean:
rm -f $(LIBRARY_LINK) $(LIBRARY) pacparser.o pactester pymod/pacparser_o_buildstamp jsapi_buildstamp
rm -rf dist
Expand Down

0 comments on commit 106c6d7

Please sign in to comment.