Skip to content

Commit

Permalink
Use --volume, upgrade actions, set Git permissions
Browse files Browse the repository at this point in the history
Also add unzip.
  • Loading branch information
theory committed Jan 19, 2024
1 parent e0d6311 commit 926c9f6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ jobs:
matrix:
pg: [16, 15, 14, 13, 12, 11, 10, 9.6, 9.5, 9.4, 9.3, 9.2, 9.1, '9.0', 8.4, 8.3, 8.2]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build Image
run: docker build -t pgxn-tools-test .
- name: Test as root
run: "docker run --rm --mount \"type=bind,src=$(pwd)/test,dst=/repo\" pgxn-tools-test /repo/runtest.sh ${{ matrix.pg }}"
run: "docker run --rm --volume \"$(pwd)/test:/repo\" pgxn-tools-test /repo/runtest.sh ${{ matrix.pg }}"
- name: Test as non-root
run: "docker run --rm --mount \"type=bind,src=$(pwd)/test,dst=/repo\" -e AS_USER=worker pgxn-tools-test /repo/runtest.sh ${{ matrix.pg }}"
run: "docker run --rm --volume \"$(pwd)/test:/repo\" -e AS_USER=worker pgxn-tools-test /repo/runtest.sh ${{ matrix.pg }}"

publish:
# Publish for a tag starting with v.
name: Push to Docker Hub
Expand All @@ -27,10 +28,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: pgxn/pgxn-tools
tags: |
Expand All @@ -42,13 +43,13 @@ jobs:
org.opencontainers.image.title=PGXN Tools
org.opencontainers.image.licenses=PostgreSQL
- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push
# https://github.com/marketplace/actions/build-and-push-docker-images
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN chmod +x /usr/local/bin/apt.postgresql.org.sh \
&& apt-get install -y --no-install-recommends \
build-essential clang llvm llvm-dev llvm-runtime \
pgxnclient libtap-parser-sourcehandler-pgtap-perl sudo gosu \
ca-certificates gnupg2 zip curl git libicu-dev libxml2 locales ssl-cert \
ca-certificates gnupg2 zip unzip curl git libicu-dev libxml2 locales ssl-cert \
&& apt-get -y purge postgresql-client-common \
&& apt-get clean \
&& rm -rf /var/cache/apt/* /var/lib/apt/lists/* \
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PGXN Extension Build and Test Tools Docker Image
[![Test & Release Status](https://github.com/pgxn/docker-pgxn-tools/workflows/CI/CD/badge.svg)](https://github.com/pgxn/docker-pgxn-tools/actions)

``` sh
docker run -it --rm -w /repo --mount "type=bind,src=$(pwd),dst=/repo" pgxn/pgxn-tools \
docker run -it --rm -w /repo --volume "$PWD:/repo" pgxn/pgxn-tools \
sh -c 'pg-start 12 && pg-build-test'
```

Expand Down Expand Up @@ -32,24 +32,24 @@ with `sudo` privileges (already used by `pg-start` and `pg-build-test`):

``` sh
docker run -it --rm -w /repo -e AS_USER=worker \
--mount "type=bind,src=$(pwd),dst=/repo" pgxn/pgxn-tools \
--volume "$PWD:/repo" pgxn/pgxn-tools \
sh -c 'sudo pg-start 14 && pg-build-test'
```

The created user will have the UID 1001 unless `LOCAL_UID` is passed, which can
usefully be set to the local UID so that the user has permission to access files
in a mounted directory:
in a volume:

``` sh
docker run -it --rm -w /repo -e AS_USER=worker -e LOCAL_UID=$(id -u) \
--mount "type=bind,src=$(pwd),dst=/repo" pgxn/pgxn-tools \
--volume "$PWD:/repo" pgxn/pgxn-tools \
sh -c 'sudo pg-start 14 && pg-build-test'
```

If no `LOCAL_UID` is set but `GITHUB_EVENT_PATH` is set (as it is in GitHub
workflows), the UID will be set to the same value as the owner of the
`GITHUB_EVENT_PATH` file. This allows the user to have full access to the
GitHub-mounted project directory.
GitHub project volume.

### Postgres User

Expand Down
1 change: 1 addition & 0 deletions bin/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ if [ $USER_ID == 0 ]; then
fi
fi

git config --global --add safe.directory "$PWD"
echo "Starting with UID $USER_ID"
useradd --system --create-home --shell /bin/bash -g root -G sudo -u $USER_ID "$AS_USER"
export HOME="/home/$AS_USER"
Expand Down
2 changes: 1 addition & 1 deletion bin/pgxn-bundle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ VERSION=${PGXN_DIST_VERSION:-$(perl -MJSON=decode_json -E 'say decode_json(join
# Now bundle up the distribution for release.
release=${DISTNAME}-${VERSION}
echo "Bundling $release.zip..."
if [ true == "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
if [ "true" == "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
git archive --format zip --prefix=${release}/ --output ${release}.zip HEAD
else
mkdir /tmp/$release
Expand Down

0 comments on commit 926c9f6

Please sign in to comment.