Skip to content

Commit

Permalink
ci: added github action for binary releases (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercurial authored May 9, 2024
1 parent 6f90ed8 commit 33dc8d6
Show file tree
Hide file tree
Showing 4 changed files with 175 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
122 changes: 122 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
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: Set up QEMU
uses: docker/setup-qemu-action@v1

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

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build Docker image for AMD64 and ARM64
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
tags: mumak:latest
push: false
platforms: linux/amd64
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache
load: true

- name: Run Docker container and extract artifacts (AMD64)
run: |
docker run -e POSTGRES_PASSWORD=password -d --name app mumak:latest
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/
docker stop app
tar -czvf mumak-artifacts-amd64.tar.gz -C artifacts .
- name: Upload Tarred Artifacts (AMD64)
uses: actions/upload-artifact@v2
with:
name: mumak-artifacts-amd64
path: ./mumak-artifacts-amd64.tar.gz

# - name: Run Docker container and extract artifacts (ARM64)
# run: |
# docker run -e POSTGRES_PASSWORD=password -d --name app-arm mumak:latest
# mkdir -p artifacts-arm
# docker cp app-arm:/source/target/release/mumak-pg16/usr/share/postgresql/16/extension/mumak.control ./artifacts-arm/
# docker cp app-arm:/source/target/release/mumak-pg16/usr/lib/postgresql/16/lib/mumak.so ./artifacts-arm/
# SQL_FILE=$(docker exec app-arm sh -c "ls /source/target/release/mumak-pg16/usr/share/postgresql/16/extension/mumak--*.sql")
# docker cp "app-arm:$SQL_FILE" ./artifacts-arm/
# docker stop app-arm
# tar -czvf mumak-artifacts-arm64.tar.gz -C artifacts-arm .

# - name: Upload Tarred Artifacts (ARM64)
# uses: actions/upload-artifact@v2
# with:
# name: mumak-artifacts-arm64
# path: ./mumak-artifacts-arm64.tar.gz

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

# - name: Download Tarred Artifacts (ARM64)
# uses: actions/download-artifact@v2
# with:
# name: mumak-artifacts-arm64

- 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 (AMD64)
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-amd64.tar.gz
asset_name: mumak-artifacts-amd64.tar.gz
asset_content_type: application/gzip

# - name: Upload Release Asset (ARM64)
# 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-arm64.tar.gz
# asset_name: mumak-artifacts-arm64.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 33dc8d6

Please sign in to comment.