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

github: Publish docker image to Docker Hub #2

Merged
merged 1 commit into from
May 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 51 additions & 29 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,62 @@ on:
branches:
- master
pull_request:
workflow_dispatch:

env:
IMAGE: endlessm/eos-activation-server

jobs:
build:
name: Build Docker Image
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build Docker Image
run: docker build --tag=eos-activation-server .
- name: Save Docker Image
run: docker save eos-activation-server > docker-image.tar
- name: Upload Artifact
uses: actions/upload-artifact@v2
- name: Checkout
uses: actions/checkout@v4

- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
name: image
path: docker-image.tar
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

tests:
name: Integration Tests
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get Docker Image
uses: actions/download-artifact@v2
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE }}
tags: |
# set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and export to Docker
uses: docker/build-push-action@v5
with:
context: .
load: true
pull: true
tags: test-server:latest

- name: Run Redis
run: docker run -d --rm --network=host --name=redis redis:5-alpine

- name: Run server
run: docker run -d --rm --network=host --name=server test-server:latest

- name: Run tests
run: docker run --rm --network=host test-server:latest npm test

- name: Stop server
run: docker stop server

- name: Stop Redis
run: docker stop redis

- name: Build and push to Docker Hub
uses: docker/build-push-action@v5
with:
name: image
- name: Load Docker Image
run: docker load < docker-image.tar
- name: Install Docker Images
run: docker run -d --name=redis --network=host redis:5-alpine
- name: Run Server
run: docker run -d --name=server --network=host --rm --name=eos-activation-server eos-activation-server
- name: Run Tests
run: docker run --rm --network=host eos-activation-server npm test
- name: Remove Docker Images
run: docker rm -f redis server
context: .
labels: ${{ steps.meta.outputs.labels }}
push: ${{ github.ref == 'refs/heads/master' }}
tags: ${{ steps.meta.outputs.tags }}
Loading