Build and push image📦 #34
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and push image📦 | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "00 17 * * SAT" | |
push: | |
branches: ["http3"] | |
# pull_request: | |
# branches: ["http3"] | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
if: github.actor == 'ammnt' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4.1.1 | |
- name: Install cosign | |
if: github.event_name != 'pull_request' | |
uses: sigstore/cosign-installer@v3.3.0 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@v3.0.0 | |
- name: Log into ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3.0.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Log into Docker Hub | |
uses: docker/login-action@v3.0.0 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5.0.0 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Build the Docker image | |
id: build | |
uses: docker/build-push-action@v5.1.0 | |
with: | |
provenance: false | |
context: . | |
platforms: linux/amd64 | |
load: ${{ github.event_name != 'pull_request' }} | |
tags: | | |
${{ steps.meta.outputs.tags }} | |
ammnt/angie:http3 | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Test the Docker image | |
run: | | |
docker run --name angie --restart unless-stopped -p 127.0.0.1:8080:8080/tcp -d ammnt/angie:http3 | |
curl -vvv http://127.0.0.1:8080 || exit 1 | |
- name: Push the Docker image | |
id: push | |
uses: docker/build-push-action@v5.1.0 | |
with: | |
provenance: false | |
context: . | |
platforms: linux/amd64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: | | |
${{ steps.meta.outputs.tags }} | |
ammnt/angie:http3 | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Sign the published Docker image | |
if: ${{ github.event_name != 'pull_request' }} | |
env: | |
COSIGN_EXPERIMENTAL: "true" | |
run: | | |
cosign sign -y \ | |
-a "repo=${{ github.repository }}" \ | |
-a "workflow=${{ github.workflow }}" \ | |
-a "ref=${{ github.sha }}" \ | |
ghcr.io/ammnt/angie:@${{ steps.push.outputs.digest }} | |
cosign sign -y \ | |
-a "repo=${{ github.repository }}" \ | |
-a "workflow=${{ github.workflow }}" \ | |
-a "ref=${{ github.sha }}" \ | |
ammnt/angie:@${{ steps.push.outputs.digest }} | |
- name: Run deploy update on the server | |
uses: appleboy/ssh-action@v1.0.1 | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
key: ${{ secrets.SERVER_KEY }} | |
port: ${{ secrets.SERVER_PORT }} | |
script: | | |
cd /home/${{ secrets.SERVER_USERNAME }}/agh | |
docker-compose pull web dns | |
docker-compose up -d web dns |