Skip to content

Commit

Permalink
Improved build and deploy workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
chipp committed Feb 21, 2024
1 parent f8ff3f4 commit 3698a78
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 34 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.DS_Store
/target
*.tar
build/

requests.sql
template-v7.db
Expand Down
63 changes: 45 additions & 18 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
matrix:
include:
- binary: alisa
arch: linux/arm64
mode: image
- binary: elisa
arch: linux/amd64
mode: binary
- binary: elizabeth
arch: linux/arm64
mode: image
- binary: isabel
arch: linux/amd64
mode: binary

steps:
- uses: actions/checkout@v4
Expand All @@ -32,28 +32,53 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@master

- name: Build and push image
- name: Build image
run: |
IMAGE_ID=ghcr.io/chipp/${{ matrix.binary }}
docker buildx build . --file bin/${{ matrix.binary }}/Dockerfile \
--push \
--platform ${{ matrix.arch }} \
--load \
--progress plain \
--tag $IMAGE_ID:latest \
--build-arg VERSION="0.1.${{ github.run_number }}" \
--label "org.opencontainers.image.source=https://github.com/${{ github.repository }}" \
--cache-from=type=registry,ref=$IMAGE_ID:cache \
--cache-to=type=registry,ref=$IMAGE_ID:cache,mode=max
- name: Compose arm64 runnable image
if: ${{ matrix.mode }} == "image"
run: |
docker ps -a
docker run --rm -v "$PWD/build:/build" ghcr.io/chipp/${{ matrix.binary }}:latest \
cp /root/${{ matrix.binary }} /build/${{ matrix.binary }}
docker buildx build . --file conf/arm64.Dockerfile \
--push \
--progress plain \
--tag $IMAGE_ID:latest \
--build-arg BINARY=${{ matrix.binary }} \
--label "org.opencontainers.image.source=https://github.com/${{ github.repository }}"
- name: Extract arm64 binary
if: ${{ matrix.mode }} == "binary"
run: |
docker run --rm -v "$PWD/build:/build" ghcr.io/chipp/${{ matrix.binary }}:latest \
cp /root/${{ matrix.binary }} /build/${{ matrix.binary }}
- name: Archive arm64 artifact
if: ${{ matrix.mode }} == "binary"
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.binary }}
path: build/${{ matrix.binary }}
retention-days: 1

deploy:
runs-on: ubuntu-latest
needs: push
steps:
- uses: actions/checkout@v4

- name: Log into registry
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin

- name: Add ssh key
run: |
mkdir ~/.ssh/
Expand Down Expand Up @@ -85,13 +110,15 @@ jobs:
ssh [email protected] \
"cd /web/lisa && docker compose down --remove-orphans --rmi all && docker compose up -d"
- name: Extract elisa
run: |
docker run --rm -v "$PWD/build:/build" ghcr.io/chipp/elisa:latest cp /root/elisa /build/elisa
- name: Download elisa
uses: actions/download-artifact@v4
with:
name: elisa

- name: Extract isabel
run: |
docker run --rm -v "$PWD/build:/build" ghcr.io/chipp/isabel:latest cp /root/isabel /build/isabel
- name: Download isabel
uses: actions/download-artifact@v4
with:
name: isabel

- name: Deploy elisa and isabel
run: |
Expand All @@ -104,5 +131,5 @@ jobs:
ssh -v [email protected] "echo test"
ssh [email protected] "sudo service elisa stop && sudo service isabel stop"
scp build/elisa build/isabel [email protected]:/usr/local/bin
scp elisa isabel [email protected]:/usr/local/bin
ssh [email protected] "sudo service elisa start && sudo service isabel start"
16 changes: 1 addition & 15 deletions bin/alisa/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/chipp/build.rust.arm64_musl:1.76.0_1 AS builder
FROM ghcr.io/chipp/build.rust.arm64_musl:1.76.0_1

WORKDIR /home/rust/src
RUN USER=rust \
Expand Down Expand Up @@ -50,17 +50,3 @@ RUN sed -i "s/version = \"0.1.0\"/version = \"${VERSION}\"/g" bin/alisa/Cargo.to
RUN cargo build --release -p alisa && \
mv target/aarch64-unknown-linux-musl/release/alisa ./ && \
rm -rf target/aarch64-unknown-linux-musl/release/ target/release/

FROM alpine:3.18.4
RUN apk --no-cache add ca-certificates && update-ca-certificates
RUN apk --no-cache add tzdata && \
cp /usr/share/zoneinfo/Europe/Vilnius /etc/localtime && \
echo "Europe/Vilnius" > /etc/timezone && \
apk del tzdata

WORKDIR /root/
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
ENV SSL_CERT_DIR=/etc/ssl/certs
ENV RUST_BACKTRACE=full

COPY --from=0 /home/rust/src/alisa .
17 changes: 17 additions & 0 deletions conf/arm64.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM alpine:3.19.1

RUN apk --no-cache add ca-certificates && update-ca-certificates
RUN apk --no-cache add tzdata && \
cp /usr/share/zoneinfo/Europe/Vilnius /etc/localtime && \
echo "Europe/Vilnius" > /etc/timezone && \
apk del tzdata

WORKDIR /root/
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
ENV SSL_CERT_DIR=/etc/ssl/certs
ENV RUST_BACKTRACE=full

ARG BINARY

COPY build/${BINARY} .
CMD [ "${BINARY}" ]

0 comments on commit 3698a78

Please sign in to comment.