build: change Dockerfile #32
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
# reference: | |
# 1. https://github.com/docker/build-push-action/blob/master/docs/advanced/push-multi-registries.md | |
# 2. https://github.com/docker/build-push-action/blob/master/docs/advanced/share-image-jobs.md | |
name: Deploy to Production environment | |
on: | |
push: | |
tags: | |
- v* | |
env: | |
ARTIFACT_PATH: artifact.tar | |
BOX_NAME: oss-toolbox | |
BOX_URL: kaiyuanshe/oss-toolbox | |
DOCKER_BUILD_SUMMARY: false | |
DOCKER_BUILD_RECORD_UPLOAD: false | |
jobs: | |
deploy_docker_image: | |
name: Deploy Docker image | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Inject Environment variables | |
run: | | |
cat > .env.local <<EOF | |
${{ secrets.ENV_FILE }} | |
EOF | |
- uses: docker/setup-qemu-action@v3 | |
- uses: docker/setup-buildx-action@v3 | |
- name: Build Image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/amd64 | |
load: true | |
tags: | |
${{ env.BOX_URL }}:latest | |
- name: show docker image | |
run: | | |
docker images | |
# Slim the Docker image | |
- name: Slim Docker image | |
uses: kitabisa/docker-slim-action@v1 | |
env: | |
DSLIM_HTTP_PROBE: false | |
with: | |
target: ${{ env.BOX_URL }}:latest | |
tag: 'slim' | |
- name: Pick Docker Compose | |
run: | | |
mkdir ./build | |
docker save ${{ env.BOX_URL }}:slim -o ${{ env.ARTIFACT_PATH }} | |
chmod 664 ${{ env.ARTIFACT_PATH }} | |
mv ${{ env.ARTIFACT_PATH }} ./docker-compose.yml ./start.sh ./build | |
- name: Transport Image | |
uses: appleboy/[email protected] | |
with: | |
source: ./build/*.* | |
target: /tmp/${{ env.BOX_NAME }} | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USER }} | |
password: ${{ secrets.SSH_KEY }} | |
strip_components: 1 | |
- name: Run Image | |
uses: garygrossgarten/github-action-ssh@release | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USER }} | |
password: ${{ secrets.SSH_KEY }} | |
command: | | |
mkdir -p ~/${{ env.BOX_NAME }} | |
cd /tmp/${{ env.BOX_NAME }} | |
mv docker-compose.yml start.sh ~/${{ env.BOX_NAME }} | |
cd ~/${{ env.BOX_NAME }} | |
chmod +x start.sh | |
echo '${{ secrets.SSH_KEY }}' | sudo -S ./start.sh /tmp/${{ env.BOX_NAME }}/${{ env.ARTIFACT_PATH }} |