Skip to content

Commit

Permalink
base code for ci pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercurial committed May 8, 2024
1 parent 6f90ed8 commit 16fa901
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 17 deletions.
6 changes: 5 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerfile": "../Dockerfile"
"dockerfile": "../dev.Dockerfile",
"args": {
"UID": "1000",
"GID": "1000"
}
},
"containerEnv": {
"POSTGRES_PASSWORD": "Test1234"
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Build, Upload and Release

on:
push:
branches:
- main
- ci/release-binary
tags:
- 'v*'

jobs:
build-and-upload:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Build Docker image
run: docker build . -t mumak

- name: Run Docker container and extract artifacts
run: |
docker run --name app mumak
mkdir -p artifacts
docker cp app:/source/target/release/mumak-pg16/usr/share/postgresql/16/extension/mumak.control ./artifacts/
docker cp app:/source/target/release/mumak-pg16/usr/lib/postgresql/16/lib/mumak.so ./artifacts/
SQL_FILE=$(docker exec app sh -c "ls /source/target/release/mumak-pg16/usr/share/postgresql/16/extension/mumak--*.sql")
docker cp "app:$SQL_FILE" ./artifacts/
# Tar the files
tar -czvf mumak-artifacts.tar.gz -C artifacts .
- name: Upload Tarred Artifacts
uses: actions/upload-artifact@v2
with:
name: mumak-artifacts
path: ./mumak-artifacts.tar.gz

release:
if: startsWith(github.ref, 'refs/tags/')
needs: build-and-upload
runs-on: ubuntu-latest
steps:
- name: Download Tarred Artifacts
uses: actions/download-artifact@v2
with:
name: mumak-artifacts

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./mumak-artifacts.tar.gz
asset_name: mumak-artifacts.tar.gz
asset_content_type: application/gzip
19 changes: 3 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,12 @@ RUN apt update && apt -y install \
pkg-config \
sudo

# Temporary to make vscode extension work since its running under root
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# Add postgres to the sudoers with no password prompt for specific commands
RUN echo "postgres ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/postgres

RUN chown -R postgres:postgres /usr/share/postgresql
RUN chown -R postgres:postgres /usr/lib/postgresql
# Using su instead of USER since dev container doesn't seem to like USER docker directive
RUN su - postgres -c 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y'

RUN echo 'export PATH="/var/lib/postgresql/.cargo/bin:${PATH}"' >> /var/lib/postgresql/.bashrc
RUN echo 'export USER=postgres' >> /var/lib/postgresql/.bashrc

RUN su - postgres -c 'cargo install --locked cargo-pgrx && cargo pgrx init'
RUN cargo install --locked cargo-pgrx && cargo pgrx init

WORKDIR /source
COPY ./extension ./
RUN sudo chown -R postgres:postgres /source
RUN su - postgres -c 'cd /source && cargo pgrx install'

COPY ./init-db.sh /docker-entrypoint-initdb.d/
RUN cargo pgrx package
45 changes: 45 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM postgres:16

ARG UID=1000
ARG GID=1000
RUN usermod -u $UID postgres && groupmod -g $GID postgres
RUN apt update && apt -y install \
curl \
git \
libclang-dev \
build-essential \
libreadline-dev \
zlib1g-dev \
flex \
bison \
libxml2-dev \
libxslt-dev \
libssl-dev \
libxml2-utils \
xsltproc \
ccache \
pkg-config \
sudo

# Temporary to make vscode extension work since its running under root
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

# Add postgres to the sudoers with no password prompt for specific commands
RUN echo "postgres ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/postgres

RUN chown -R postgres:postgres /usr/share/postgresql
RUN chown -R postgres:postgres /usr/lib/postgresql
# Using su instead of USER since dev container doesn't seem to like USER docker directive
RUN su - postgres -c 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y'

RUN echo 'export PATH="/var/lib/postgresql/.cargo/bin:${PATH}"' >> /var/lib/postgresql/.bashrc
RUN echo 'export USER=postgres' >> /var/lib/postgresql/.bashrc

RUN su - postgres -c 'cargo install --locked cargo-pgrx && cargo pgrx init'

WORKDIR /source
COPY ./extension ./
RUN sudo chown -R postgres:postgres /source
RUN su - postgres -c 'cd /source && cargo pgrx install'

COPY ./init-db.sh /docker-entrypoint-initdb.d/

0 comments on commit 16fa901

Please sign in to comment.