Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ci): add docker image push workflow #2

Merged
merged 21 commits into from
Sep 25, 2024
Merged
72 changes: 72 additions & 0 deletions .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Tag and push all docker

on:
workflow_dispatch: {}
push:
tags:
- v*

env:
CARGO_TERM_COLOR: always
DOCKER_USERNAME: ${{ github.actor }}

jobs:
build:
name: Build all images
runs-on: ubuntu-20.04
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Run make golang-docker
run: |
make golang-docker

- name: Put all docker images in temp dir
run: |
docker image ls | grep 'us-.*oplabs.*latest' | sed 's/ *latest.*//' | xargs -L1 -I % echo 'docker image save % -o /tmp/%.tar' | sed 's:/tmp/.*/\(.*\.tar\):/tmp/\1:' | bash

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: op-images
path: /tmp/op-*.tar

push:
name: Tag and push all images
runs-on: ubuntu-20.04
needs: build
strategy:
matrix:
image: [op-node, op-batcher, op-proposer, op-challenger, op-supervisor, op-dispute-mon]
permissions:
packages: write
contents: read
steps:
- name: Download built artifact
uses: actions/download-artifact@v4
with:
name: op-images
path: op-images

- name: Import image
run: |
docker image load --input op-images/${{ matrix.image }}.tar

- name: Log in to Docker
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io --username ${DOCKER_USERNAME} --password-stdin

- name: Tag image versions
run: |
docker image tag us-docker.pkg.dev/oplabs-tools-artifacts/images/${{ matrix.image }} ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}

- name: Tag versions
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
docker image tag ghcr.io/${{ github.repository_owner }}/${{ matrix.image }} ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}:${{ github.ref_name }}

- name: Push images
run: |
docker image push -a ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}