-
Notifications
You must be signed in to change notification settings - Fork 2
71 lines (62 loc) · 1.97 KB
/
build-and-push.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: Build and push container image
on:
workflow_dispatch:
push:
branches:
- "**" # Push to any branch
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
# Don't push because pushes to the public ECR repository seem to fail
NO_PUSH: "true"
- name: Push to Amazon ECR
if: github.event_name == 'push'
run: |
short_sha=$(echo ${{ github.sha }} | cut -c1-12)
docker push ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:${short_sha}
- name: Push latest tag to Amazon ECR from main branch
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
docker push ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:latest