Skip to content

Commit

Permalink
Merge pull request #88 from erykoff/containers
Browse files Browse the repository at this point in the history
Change to GHA for building Docker container.
  • Loading branch information
erykoff authored Apr 6, 2023
2 parents 0a94534 + 1f12a88 commit d3a8b43
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 20 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI

"on":
push:
tags:
- "*"
pull_request: {}

jobs:
build:

runs-on: ubuntu-latest

# Only do Docker builds of tagged releases.
if: >
startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Define the Docker tag
id: vars
run: |
echo GITHUB_REF: $GITHUB_REF
echo GITHUB_HEAD_REF: $GITHUB_HEAD_REF
echo ::set-output name=tag::$(bin/docker-tag.sh)
- name: Print the tag
id: print
run: echo ${{ steps.vars.outputs.tag }}

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

- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
ghcr.io/erykoff/redmapper:${{ steps.vars.outputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max
40 changes: 20 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ FROM ubuntu:22.04

ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
ENV PATH /opt/conda/bin:$PATH
ARG TAG

RUN apt-get update && \
apt-get install -y autoconf gcc gfortran g++ make wget gsl-bin git libgsl-dev && apt-get clean all
apt-get -y upgrade
RUN apt-get install -y curl tini

RUN apt-get install -y curl grep sed dpkg tini
RUN apt-get clean

RUN /usr/sbin/groupadd -g 1000 user && \
/usr/sbin/useradd -u 1000 -g 1000 -d /opt/redmapper redmapper && \
mkdir /opt/redmapper && chown redmapper.user /opt/redmapper && \
chown redmapper.user /opt
/usr/sbin/useradd -u 1000 -g 1000 -d /opt/redmapper redmapper && \
mkdir /opt/redmapper && chown redmapper.user /opt/redmapper && \
chown -R redmapper.user /opt

COPY . /opt/redmapper/workdir
RUN chown -R redmapper.user /opt/redmapper/workdir

USER redmapper
RUN wget --quiet https://github.com/conda-forge/miniforge/releases/download/22.9.0-2/Mambaforge-22.9.0-2-Linux-x86_64.sh -O ~/miniforge.sh && \
/bin/bash ~/miniforge.sh -b -p /opt/conda && \
rm ~/miniforge.sh

RUN curl -L -o ~/mambaforge.sh https://github.com/conda-forge/miniforge/releases/download/23.1.0-1/Mambaforge-23.1.0-1-Linux-x86_64.sh && \
/bin/bash ~/mambaforge.sh -b -p /opt/conda && \
rm ~/mambaforge.sh
RUN . /opt/conda/etc/profile.d/conda.sh && conda create --yes --name redmapper-env
RUN echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
echo "conda activate redmapper-env" >> ~/.bashrc
RUN echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/startup.sh && \
echo "conda activate redmapper-env" >> ~/startup.sh
RUN echo ". /opt/conda/etc/profile.d/conda.sh" > /opt/redmapper/startup.sh && \
echo "conda activate redmapper-env" >> /opt/redmapper/startup.sh

RUN . /opt/conda/etc/profile.d/conda.sh && conda activate redmapper-env && \
conda install --yes python=3.10 numpy scipy astropy matplotlib pyyaml fitsio esutil healpy healsparse hpgeom && \
conda clean -af --yes
mamba install --yes python=3.10 numpy scipy astropy matplotlib pyyaml gsl c-compiler fitsio esutil healpy healsparse hpgeom && \
conda clean -af --yes

LABEL redmapper-tag="${TAG}"

RUN . /opt/conda/etc/profile.d/conda.sh && conda activate redmapper-env && cd ~/ && \
git clone https://github.com/erykoff/redmapper --branch=${TAG} && cd ~/redmapper && \
cd ~/redmapper && python setup.py install
RUN . /opt/conda/etc/profile.d/conda.sh && conda activate redmapper-env && \
cd /opt/redmapper/workdir && \
python setup.py install

ENTRYPOINT [ "/usr/bin/tini", "--" ]
CMD [ "/bin/bash", "-lc" ]
14 changes: 14 additions & 0 deletions bin/docker-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Determine the tag for Docker images based on GitHub Actions environment
# variables.

set -eo pipefail

if [ -n "$GITHUB_HEAD_REF" ]; then
# For pull requests
echo ${GITHUB_HEAD_REF} | sed -E 's,/,-,g'
else
# For push events
echo ${GITHUB_REF} | sed -E 's,refs/(heads|tags)/,,' | sed -E 's,/,-,g'
fi

0 comments on commit d3a8b43

Please sign in to comment.