Skip to content

Install and use pre-commit (#26) #109

Install and use pre-commit (#26)

Install and use pre-commit (#26) #109

name: Build and push container image
on:
workflow_dispatch:
push:
branches:
- "**" # Push to any branch
tags:
- "**"
paths-ignore:
- "README.md"
- "LICENSE"
pull_request:
branches:
- main
env:
REGISTRY: public.ecr.aws
NAMESPACE: nasa-veda
IMAGE_NAME: pangeo-notebook-veda-image
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
install: true
- name: Configure AWS Credentials
if: github.event_name == 'push'
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR Public
if: github.event_name == 'push'
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- uses: int128/create-ecr-repository-action@v1
if: github.event_name == 'push'
with:
repository: ${{ env.IMAGE_NAME}}
public: true
- name: Build container image
uses: jupyterhub/repo2docker-action@master
with:
DOCKER_REGISTRY: ${{ env.REGISTRY }}
IMAGE_NAME: ${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}
REPO_DIR: /srv/repo
NO_PUSH: "true"
- name: Set image tag
id: set_tag
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo "IMAGE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
else
echo "IMAGE_TAG=$(echo ${{ github.sha }} | cut -c1-12)" >> $GITHUB_OUTPUT
fi
- name: Tag and push image
if: github.event_name == 'push'
env:
IMAGE_TAG: ${{ steps.set_tag.outputs.IMAGE_TAG }}
run: |
FULL_IMAGE_NAME=${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}
docker tag $FULL_IMAGE_NAME:latest $FULL_IMAGE_NAME:$IMAGE_TAG
docker push $FULL_IMAGE_NAME:$IMAGE_TAG || exit 1
echo "Pushed image: $FULL_IMAGE_NAME:$IMAGE_TAG"
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
docker push $FULL_IMAGE_NAME:latest || exit 1
echo "Pushed image: $FULL_IMAGE_NAME:latest"
fi