forked from convince-project/AS2FM
-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (54 loc) · 2.27 KB
/
docker.yml
File metadata and controls
58 lines (54 loc) · 2.27 KB
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
name: Docker
on:
push:
branches:
- main
pull_request:
env:
OWNER: '${{ github.repository_owner }}'
# TODO hardcoded, should instead get github.repository_owner and convert to lowercase
# (This breaks tests in forks)
OWNER_LC: 'nevertools'
REGISTRY_IMAGE: ghcr.io/$OWNER_LC/moco
REGISTRY_IMAGE_LATEST: ghcr.io/$OWNER_LC/moco:latest
RAW_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
build:
name: Build and push docker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Pull latest image for caching
run: |
docker pull ${{ env.REGISTRY_IMAGE_LATEST }}
continue-on-error: true
- name: Also pull this branch's image for caching
run: |
export BRANCH_NAME=$(echo ${{ env.RAW_BRANCH_NAME }} | sed 's/\//-/g')
docker pull ${{ env.REGISTRY_IMAGE }}:$BRANCH_NAME
continue-on-error: true
- name: Build Docker image
run: docker build -f .docker/Dockerfile -t ${{ env.REGISTRY_IMAGE_LATEST }} .
- name: Push to gh registry with sha and branch
if: ${{ !github.event.pull_request.head.repo.fork }}
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $OWNER_LC --password-stdin
# tag with sha and push
docker tag ${{ env.REGISTRY_IMAGE_LATEST }} ${{ env.REGISTRY_IMAGE }}:${{ github.sha }}
docker push ${{ env.REGISTRY_IMAGE }}:${{ github.sha }}
# tag with branch name and push
export BRANCH_NAME=$(echo ${{ env.RAW_BRANCH_NAME }} | sed 's/\//-/g')
docker tag ${{ env.REGISTRY_IMAGE_LATEST }} ${{ env.REGISTRY_IMAGE }}:$BRANCH_NAME
docker push ${{ env.REGISTRY_IMAGE }}:$BRANCH_NAME
echo "TAG_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Testing
run: docker run ${{ env.REGISTRY_IMAGE_LATEST }} pytest /colcon_ws/src/moco
- name: Push to gh registry with latest if this is main
if: github.ref == 'refs/heads/main'
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $OWNER_LC --password-stdin
# only from main we actually push to latest
docker push ${{ env.REGISTRY_IMAGE_LATEST }}
echo "TAG_NAME=latest" >> $GITHUB_ENV